|
這是電子琴的程式: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(inputPinG, INPUT);
pinMode(inputPinF, INPUT);
pinMode(inputPinE, INPUT);
pinMode(inputPinD, INPUT);
pinMode(inputPinC, INPUT);
pinMode(inputPinB, INPUT);
pinMode(inputPinA, INPUT);
pinMode(BuzzerPin, OUTPUT);
}
void loop() {
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 (valG == HIGH){
digitalWrite(BuzzerPin, HIGH);
delayMicroseconds(1915);
digitalWrite(BuzzerPin, LOW);
delayMicroseconds(1915);
}
else if (valF == HIGH){
digitalWrite(BuzzerPin, HIGH);
delayMicroseconds(1700);
digitalWrite(BuzzerPin, LOW);
delayMicroseconds(1700);
}
else if (valE == HIGH){
digitalWrite(BuzzerPin, HIGH);
delayMicroseconds(1519);
digitalWrite(BuzzerPin, LOW);
delayMicroseconds(1519);
}
else if (valD == HIGH){
digitalWrite(BuzzerPin, HIGH);
delayMicroseconds(1432);
digitalWrite(BuzzerPin, LOW);
delayMicroseconds(1432);
}
else if (valC == HIGH){
digitalWrite(BuzzerPin, HIGH);
delayMicroseconds(1275);
digitalWrite(BuzzerPin, LOW);
delayMicroseconds(1275);
}
else if (valB == HIGH){
digitalWrite(BuzzerPin, HIGH);
delayMicroseconds(1136);
digitalWrite(BuzzerPin, LOW);
delayMicroseconds(1136);
}
else if (valA == HIGH){
digitalWrite(BuzzerPin, HIGH);
delayMicroseconds(990);
digitalWrite(BuzzerPin, LOW);
delayMicroseconds(990);
}
else digitalWrite(BuzzerPin, LOW);
}
最大的問題就是輸出接了蜂鳴器,就響個不停,完全不知道是怎麼回事= =
我連接腳都還沒接,光接喇叭就響個不停了,真的不知到問題出在哪= = |
|