Student Page

Harold O. Levy Acceptable Use Policy

Student Handbook 17-18

 

CS4ALL

Lightshow Arduino Code

int red1 = 13;
int yellow1 = 12;
int green1 = 11;
int red2 = 10;
int yellow2 = 9;
int green2 = 8;

void setup() {
// put your setup code here, to run once:

pinMode(red1, OUTPUT);
pinMode(yellow1, OUTPUT);
pinMode(green1, OUTPUT);
pinMode(red2, OUTPUT);
pinMode(yellow2, OUTPUT);
pinMode(green2, OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
lightshow();
delay(20000);
}

void lightshow(){
// green off, yellow on for 3 seconds
digitalWrite(green1, LOW);
digitalWrite(yellow1, HIGH);
delay(3000);

// turn off yellow, then turn red on for 5 seconds
digitalWrite(yellow2, LOW);
digitalWrite(red2, HIGH);
delay(5000);

// red and yellow on for 2 seconds (red is already on though)
digitalWrite(yellow1, HIGH);
delay(2000);

// turn off red and yellow, then turn on green
digitalWrite(yellow2, LOW);
digitalWrite(red2, LOW);
digitalWrite(green2, HIGH);
delay(3000);
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: