top of page
Writer's pictureSophia Chan

[Arduino Blink] Sophia Chan






int button = 13;


int greenC = 12;

int yellowC = 11;

int redC = 10;

int greenP = 9;

int redP = 8;


int buttonDelay = 800;

int lightDelay = 600;

int stopTime = 5000;


void setup() {

pinMode(button, INPUT);

for(int i=12; i>7; i--){

pinMode(i, OUTPUT);

}

}


void lightBlink(int led, int interval, int blinks) {

for (int i = 0; i < blinks; i++){

digitalWrite(led, LOW);

delay(interval);

digitalWrite(led, HIGH);

delay(interval);

}

}


void loop() {

digitalWrite(greenC, HIGH);

digitalWrite(redP, HIGH);


if (digitalRead(button)==LOW){

delay(buttonDelay);

digitalWrite(greenC, LOW);

digitalWrite(yellowC, HIGH);

delay(lightDelay);

lightBlink(yellowC, 300, 5);

digitalWrite(yellowC, LOW);

digitalWrite(redP, LOW);

digitalWrite(redC, HIGH);

digitalWrite(greenP, HIGH);

delay(stopTime);


lightBlink(greenP, 300, 5);

digitalWrite(greenP, LOW);

digitalWrite(redC, LOW);

digitalWrite(redP, HIGH);

digitalWrite(greenC, HIGH);

}

}

32 views0 comments

Recent Posts

See All

コメント


bottom of page