- When I press the button once, sequence s1() plays.
- When I press the button twice, sequence s2() plays.
- When I press the button thrice, sequence s3() plays.
- When I press the button 4 times, sequence s4() plays.
const int buttonPin = 10;
int buttonState = 0;
void setup(){
Serial.begin(9600);
//initialize pin 2 - 9 as output
for(int i=2;i<=9;i++){
pinMode(i,OUTPUT);
}
pinMode(buttonPin, INPUT);
}
void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
s1();
s2();
s3();
s4();
}
}
void s1() {
int i = 2 ;
for(int z=0;z<=1;z++) {
for(int x=i;x<=9;x++) {
digitalWrite(i,HIGH);
digitalWrite(x-1,LOW);
delay(500);
i = i + 1;
}
i = 2;
if(i = 2) {
digitalWrite(9,LOW);
}
}
}
void s2(){
int y = 9;
for(int i=0;i<=1;i++) {
for(int x=2;x<=5;x++) {
if(y>=1) {
digitalWrite(x,HIGH);
digitalWrite(y,HIGH);
delay(500);
y = y - 1;
}
}
off();
y = 9;
delay(500);
}
}
void s3() {
for(int i=0;i<=2;i++) {
for(int z=2; z<=9;z++) {
if(z % 2 == 0) {
digitalWrite(z,HIGH);
}
}
delay(500);
for(int z=2; z<=9;z++) {
if(z % 2 == 0) {
digitalWrite(z,LOW);
}
}
delay(500);
for(int z=2; z<=9;z++) {
if(z % 2 != 0) {
digitalWrite(z,HIGH);
}
}
delay(500);
for(int z=2; z<=9;z++) {
if(z % 2 != 0) {
digitalWrite(z,LOW);
}
}
delay(500);
}
}
void s4() {
for(int i=0;i<=2;i++) {
for(int x=2;x<=9;x++) {
digitalWrite(x,HIGH);
delay(500);
}
off();
delay(500);
}
}
void off() {
for(int i=2;i<=9;i++) {
digitalWrite(i,LOW);
}
}