Uploaded by ridalal832

LED SequenceAndPushButton

advertisement
int sec = 55;
int ledPin = 2;
int ledPin1 = 7;
int dirChange = 1;
int seqChange = 0;
int buttonSt = 0;
void setup() {
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, INPUT);
}
void loop() {
buttonSt = digitalRead(9);
if (buttonSt == HIGH) {
seqChange++;
if (seqChange == 5) {
seqChange = 0;
}
delay(100);
}
if(seqChange == 0) {
digitalWrite(ledPin, HIGH);
delay(sec);
digitalWrite(ledPin, LOW);
delay(sec);
ledPin = ledPin + dirChange;
if (ledPin == 9) {
ledPin = 2;
}
}else if(seqChange == 1) {
digitalWrite(ledPin, HIGH);
delay(sec);
digitalWrite(ledPin, LOW);
delay(sec);
ledPin = ledPin + dirChange;
if (ledPin == 8) {
dirChange = -1;
} else if (ledPin == 2) {
dirChange = 1;
}
}else if(seqChange == 2) {
digitalWrite(ledPin, HIGH);
digitalWrite(ledPin1, HIGH);
delay(sec);
digitalWrite(ledPin, LOW);
digitalWrite(ledPin1, LOW);
delay(sec);
ledPin = ledPin + dirChange;
ledPin1 = ledPin1 - dirChange;
if (ledPin == 8) {
dirChange = -1;
}
if (ledPin == 2) {
dirChange = 1;
}
}else if(seqChange == 3) {
digitalWrite(ledPin, HIGH);
digitalWrite(ledPin1, HIGH);
delay(sec);
digitalWrite(ledPin, LOW);
digitalWrite(ledPin1, LOW);
delay(sec);
ledPin = ledPin + dirChange;
ledPin1 = ledPin1 + dirChange;
if (ledPin1 == 8) {
dirChange = -1;
}
if (ledPin == 2) {
dirChange = 1;
}
}else {
digitalWrite(ledPin, LOW);
digitalWrite(ledPin1, LOW);
}
}
Download