Traffic light: First Arduino sketch from scratch

13 Apr

image

Simple traffic light simulator sketch.
Written on notepad on iPad and pasted into Arduino.
Shame there is no better program on iPad for creating sketches but I believe it against Apple policy to allow programming other platforms on the iPad.

/* Traffic Light sketch
*/

// Connected LED to
int greenled = 13;
int amberled = 12;
int redled = 11;

void setup() {
        pinMode (greenled, OUTPUT);
        pinMode (amberled, OUTPUT);
        pinMode (redled, OUTPUT);
}

void loop() {
        digitalWrite(redled, HIGH);                             //Start with red light
        delay(3000);                                                            //Stays red for 3 seconds
        digitalWrite(amberled, HIGH);           //Amber comes on as well
        delay(1000);                                                            //Both on for 1 second
        digitalWrite (redled, LOW);                             //Turn off red
        digitalWrite (amberled, LOW);           // Turn off amber
        digitalWrite (greenled, HIGH);          // Turn on green
        delay(5000);                                                            // Green for  5 secs
        digitalWrite (greenled, LOW);           // Turn off green
        digitalWrite (amberled, HIGH);          //Amber comes on
        delay (1000) ;                                                                  // for a second
        digitalWrite(amberled, LOW);            //Amber off ready for red
}

Advertisements

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: