Weihnachts LED s mit Melodie
LED s zum Takt anschalten
Materialien: -7 LED s nach Wahl
-Kabel
-7 Widerstände (220 Ohm)
-1 Breadboard
-1 Arduino
-1 Lautsprecher
Der Code:
int buzz = 9; // buzz an Pin 9
int ledpin = 2; // LED an Pin 2
int ledpin2 = 3;
int ledpin3 = 4;
int ledpin4 = 5;
int ledpin5 = 6;
int ledpin6 = 7;
int ledpin7 = 8;
int ledpin8 = 10;
int ledpin9 = 11;
int ledpin = 2; // LED an Pin 2
int ledpin2 = 3;
int ledpin3 = 4;
int ledpin4 = 5;
int ledpin5 = 6;
int ledpin6 = 7;
int ledpin7 = 8;
int ledpin8 = 10;
int ledpin9 = 11;
void setup() {
digitalWrite(buzz, LOW);
pinMode(buzz, OUTPUT);
pinMode(ledpin, OUTPUT);// LEDs sind Outputs
pinMode(ledpin2, OUTPUT);
pinMode(ledpin3, OUTPUT);
pinMode(ledpin4, OUTPUT);
pinMode(ledpin5, OUTPUT);
pinMode(ledpin6, OUTPUT);
pinMode(ledpin7, OUTPUT);
pinMode(ledpin8, OUTPUT);
pinMode(ledpin9, OUTPUT);
}
digitalWrite(buzz, LOW);
pinMode(buzz, OUTPUT);
pinMode(ledpin, OUTPUT);// LEDs sind Outputs
pinMode(ledpin2, OUTPUT);
pinMode(ledpin3, OUTPUT);
pinMode(ledpin4, OUTPUT);
pinMode(ledpin5, OUTPUT);
pinMode(ledpin6, OUTPUT);
pinMode(ledpin7, OUTPUT);
pinMode(ledpin8, OUTPUT);
pinMode(ledpin9, OUTPUT);
}
void loop() {
digitalWrite(buzz, LOW);
tone(buzz, 200);// gib einen ton an
digitalWrite(ledpin, HIGH);//schalte die LED1 an
delay(300);// warte 300 milli sekunden
digitalWrite(ledpin, LOW);// Schalte die LED 1 aus
noTone(buzz);// Schalte den Ton aus
delay(300); // warte 300 millisekunden bevor du den nächsten Ton angibst
digitalWrite(buzz, LOW);
tone(buzz, 200);
digitalWrite(ledpin, HIGH);
delay(300);
digitalWrite(ledpin, LOW);
noTone(buzz);
delay(300);
digitalWrite(buzz, LOW);
tone(buzz, 400);
digitalWrite(ledpin2, HIGH);
delay(300);
digitalWrite(ledpin2, LOW);
noTone(buzz);
delay(300);
digitalWrite(buzz, LOW);
tone(buzz, 400);
digitalWrite(ledpin2, HIGH);
delay(300);
digitalWrite(ledpin2, LOW);
noTone(buzz);
delay(300);
digitalWrite(buzz, LOW);
tone(buzz, 450);
digitalWrite(ledpin3, HIGH);
delay(300);
digitalWrite(ledpin3, LOW);
noTone(buzz);
delay(300);
digitalWrite(buzz, LOW);
tone(buzz, 450);
digitalWrite(ledpin3, HIGH);
delay(300);
digitalWrite(ledpin3, LOW);
noTone(buzz);
delay(300);
digitalWrite(buzz, LOW);
tone(buzz, 400);
digitalWrite(ledpin4, HIGH);
delay(300);
digitalWrite(ledpin4, LOW);
noTone(buzz);
delay(600);
digitalWrite(buzz, LOW);
tone(buzz, 350);
digitalWrite(ledpin5, HIGH);
delay(300);
digitalWrite(ledpin5, LOW);
noTone(buzz);
delay(300);
digitalWrite(buzz, LOW);
tone(buzz, 350);
digitalWrite(ledpin5, HIGH);
delay(300);
digitalWrite(ledpin5, LOW);
noTone(buzz);
delay(300);
digitalWrite(buzz, LOW);
tone(buzz, 330);
digitalWrite(ledpin6, HIGH);
delay(300);
digitalWrite(ledpin6, LOW);
noTone(buzz);
delay(300);
digitalWrite(buzz, LOW);
tone(buzz, 330);
digitalWrite(ledpin6, HIGH);
delay(300);
digitalWrite(ledpin6, LOW);
noTone(buzz);
delay(300);
digitalWrite(buzz, LOW);
tone(buzz, 320);
digitalWrite(ledpin7, HIGH);
delay(600);
digitalWrite(ledpin7, LOW);
noTone(buzz);
delay(300);
digitalWrite(buzz, LOW);
tone(buzz, 310);
digitalWrite(ledpin8, HIGH);
delay(300);
digitalWrite(ledpin8, LOW);
noTone(buzz);
delay(300);
digitalWrite(buzz, LOW);
tone(buzz, 300);
digitalWrite(ledpin9, HIGH);
delay(300);
digitalWrite(ledpin9, LOW);
noTone(buzz);
delay(5000);// warte 5 Sekunden bis alles wiederholt wird
}
digitalWrite(buzz, LOW);
tone(buzz, 200);// gib einen ton an
digitalWrite(ledpin, HIGH);//schalte die LED1 an
delay(300);// warte 300 milli sekunden
digitalWrite(ledpin, LOW);// Schalte die LED 1 aus
noTone(buzz);// Schalte den Ton aus
delay(300); // warte 300 millisekunden bevor du den nächsten Ton angibst
digitalWrite(buzz, LOW);
tone(buzz, 200);
digitalWrite(ledpin, HIGH);
delay(300);
digitalWrite(ledpin, LOW);
noTone(buzz);
delay(300);
digitalWrite(buzz, LOW);
tone(buzz, 400);
digitalWrite(ledpin2, HIGH);
delay(300);
digitalWrite(ledpin2, LOW);
noTone(buzz);
delay(300);
digitalWrite(buzz, LOW);
tone(buzz, 400);
digitalWrite(ledpin2, HIGH);
delay(300);
digitalWrite(ledpin2, LOW);
noTone(buzz);
delay(300);
digitalWrite(buzz, LOW);
tone(buzz, 450);
digitalWrite(ledpin3, HIGH);
delay(300);
digitalWrite(ledpin3, LOW);
noTone(buzz);
delay(300);
digitalWrite(buzz, LOW);
tone(buzz, 450);
digitalWrite(ledpin3, HIGH);
delay(300);
digitalWrite(ledpin3, LOW);
noTone(buzz);
delay(300);
digitalWrite(buzz, LOW);
tone(buzz, 400);
digitalWrite(ledpin4, HIGH);
delay(300);
digitalWrite(ledpin4, LOW);
noTone(buzz);
delay(600);
digitalWrite(buzz, LOW);
tone(buzz, 350);
digitalWrite(ledpin5, HIGH);
delay(300);
digitalWrite(ledpin5, LOW);
noTone(buzz);
delay(300);
digitalWrite(buzz, LOW);
tone(buzz, 350);
digitalWrite(ledpin5, HIGH);
delay(300);
digitalWrite(ledpin5, LOW);
noTone(buzz);
delay(300);
digitalWrite(buzz, LOW);
tone(buzz, 330);
digitalWrite(ledpin6, HIGH);
delay(300);
digitalWrite(ledpin6, LOW);
noTone(buzz);
delay(300);
digitalWrite(buzz, LOW);
tone(buzz, 330);
digitalWrite(ledpin6, HIGH);
delay(300);
digitalWrite(ledpin6, LOW);
noTone(buzz);
delay(300);
digitalWrite(buzz, LOW);
tone(buzz, 320);
digitalWrite(ledpin7, HIGH);
delay(600);
digitalWrite(ledpin7, LOW);
noTone(buzz);
delay(300);
digitalWrite(buzz, LOW);
tone(buzz, 310);
digitalWrite(ledpin8, HIGH);
delay(300);
digitalWrite(ledpin8, LOW);
noTone(buzz);
delay(300);
digitalWrite(buzz, LOW);
tone(buzz, 300);
digitalWrite(ledpin9, HIGH);
delay(300);
digitalWrite(ledpin9, LOW);
noTone(buzz);
delay(5000);// warte 5 Sekunden bis alles wiederholt wird
}
Erstellt: Jean Daniel Preuss (10.01.2017)
Letzte Änderung: Maximilian Stauch (28.06.2017)