|
回復 22# Curtiss
我程式這樣寫步之行不行得通,情您過目^^!
int inputPinH = 8;
int inputPinG = 7;
int inputPinF = 6;
int inputPinE = 5;
int inputPinD = 4;
int inputPinC = 3;
int inputPinB = 2;
int inputPinA = 1;
int BuzzerPin = 0;
void setup() {
pinMode(inputPinH, INPUT);
pinMode(inputPinG, INPUT);
pinMode(inputPinF, INPUT);
pinMode(inputPinE, INPUT);
pinMode(inputPinD, INPUT);
pinMode(inputPinC, INPUT);
pinMode(inputPinB, INPUT);
pinMode(inputPinA, INPUT);
pinMode(BuzzerPin, OUTPUT);
digitalWrite( 8, HIGH);
digitalWrite( 7, HIGH);
digitalWrite( 6, HIGH);
digitalWrite( 5, HIGH);
digitalWrite( 4, HIGH);
digitalWrite( 3, HIGH);
digitalWrite( 2, HIGH);
digitalWrite( 1, HIGH);
}
void loop() {
int valH = digitalRead(inputPinH);
int valG = digitalRead(inputPinG);
int valF = digitalRead(inputPinF);
int valE = digitalRead(inputPinE);
int valD = digitalRead(inputPinD);
int valC = digitalRead(inputPinC);
int valB = digitalRead(inputPinB);
int valA = digitalRead(inputPinA);
digitalWrite(BuzzerPin, LOW);
if (valA == LOW){
digitalWrite(BuzzerPin, HIGH);
delayMicroseconds(1908.397);
digitalWrite(BuzzerPin, LOW);
delayMicroseconds(1908.397);
}
else if (valB == LOW){
digitalWrite(BuzzerPin, HIGH);
delayMicroseconds(1700.68);
digitalWrite(BuzzerPin, LOW);
delayMicroseconds(1700.68);
}
else if (valC == LOW){
digitalWrite(BuzzerPin, HIGH);
delayMicroseconds(1515.152);
digitalWrite(BuzzerPin, LOW);
delayMicroseconds(1515.152);
}
else if (valD == LOW){
digitalWrite(BuzzerPin, HIGH);
delayMicroseconds(1432.665);
digitalWrite(BuzzerPin, LOW);
delayMicroseconds(1432.665);
}
else if (valE == LOW){
digitalWrite(BuzzerPin, HIGH);
delayMicroseconds(1275.51);
digitalWrite(BuzzerPin, LOW);
delayMicroseconds(1275.51);
}
else if (valF == LOW){
digitalWrite(BuzzerPin, HIGH);
delayMicroseconds(1136.364);
digitalWrite(BuzzerPin, LOW);
delayMicroseconds(1136.364);
}
else if (valG == LOW){
digitalWrite(BuzzerPin, HIGH);
delayMicroseconds(1012.146);
digitalWrite(BuzzerPin, LOW);
delayMicroseconds(1012.146);
}
else digitalWrite(BuzzerPin, LOW);
if (valH == LOW){
if (valA == LOW){
digitalWrite(BuzzerPin, HIGH);
delayMicroseconds(954.1985);
digitalWrite(BuzzerPin, LOW);
delayMicroseconds(954.1985);
}
else if (valB == LOW){
digitalWrite(BuzzerPin, HIGH);
delayMicroseconds(850.3401);
digitalWrite(BuzzerPin, LOW);
delayMicroseconds(850.3401);
}
else if (valC == LOW){
digitalWrite(BuzzerPin, HIGH);
delayMicroseconds(757.5758);
digitalWrite(BuzzerPin, LOW);
delayMicroseconds(757.5758);
}
else if (valD == LOW){
digitalWrite(BuzzerPin, HIGH);
delayMicroseconds(716.3324);
digitalWrite(BuzzerPin, LOW);
delayMicroseconds(716.3324);
}
}
} |
|