Here is the code I used. It's a bit long, so there's probably a more concise way to write it, but it works.
//melody notes:
int b = 4;
int c = 3;
int d = 2;
//bass notes:
int lb = 8;
int lc = 7;
int ld = 6;
int le = 5;
void setup() {
Serial.begin(9600);
pinMode(b, OUTPUT);
pinMode(c, OUTPUT);
pinMode(d, OUTPUT);
pinMode(lb, OUTPUT);
pinMode(lc, OUTPUT);
pinMode(ld, OUTPUT);
pinMode(le, OUTPUT);
}
void loop() {
for(int i = 0; i<5; i++){
digitalWrite(d, HIGH);
delay(400);
digitalWrite(d, LOW);
digitalWrite(c, HIGH);
delay(200);
digitalWrite(c,LOW);
digitalWrite(d, HIGH);
delay(200);
digitalWrite(d,LOW);
digitalWrite(b,HIGH);
delay(400);
digitalWrite(b,LOW);
}
digitalWrite(le,HIGH);
digitalWrite(d, HIGH);
delay(400);
digitalWrite(d, LOW);
digitalWrite(c, HIGH);
delay(200);
digitalWrite(c,LOW);
digitalWrite(d, HIGH);
delay(200);
digitalWrite(d,LOW);
digitalWrite(b,HIGH);
delay(400);
digitalWrite(b,LOW);
digitalWrite(le,LOW);
digitalWrite(ld,HIGH);
digitalWrite(d, HIGH);
delay(400);
digitalWrite(d, LOW);
digitalWrite(c, HIGH);
delay(200);
digitalWrite(c,LOW);
digitalWrite(d, HIGH);
delay(200);
digitalWrite(d,LOW);
digitalWrite(b,HIGH);
delay(400);
digitalWrite(b,LOW);
digitalWrite(ld,LOW);
digitalWrite(lc,HIGH);
digitalWrite(d, HIGH);
delay(400);
digitalWrite(d, LOW);
digitalWrite(c, HIGH);
delay(200);
digitalWrite(c,LOW);
digitalWrite(d, HIGH);
delay(200);
digitalWrite(d,LOW);
digitalWrite(b,HIGH);
delay(400);
digitalWrite(b,LOW);
digitalWrite(lc,LOW);
digitalWrite(lb,HIGH);
digitalWrite(d, HIGH);
delay(400);
digitalWrite(d, LOW);
digitalWrite(c, HIGH);
delay(200);
digitalWrite(c,LOW);
digitalWrite(d, HIGH);
delay(200);
digitalWrite(d,LOW);
digitalWrite(b,HIGH);
delay(400);
digitalWrite(b,LOW);
digitalWrite(lb,LOW);
}
No comments:
Post a Comment