More complex traffic light system

To look deeper into the code I found myself looking at a more complex system, below shows the same setup as before but this is the direction I took somewhat in the end. As you can see it adds a bit of interactability to create a pedestrian crossing system. Arduino_Traffic_Light_With_Button-1.png

To start I simply need to add in a variable to the start along with the LED names.

-int button = 12

Next is to add a setup function to add a new line, this will make the switch an input.

-pinMode (button, INPUT);

-digitalWrite(green, HIGH);

For this change, I would have to switch around the loop code to the following.

void loop() {
    if (digitalRead(button) == HIGH){
        delay(15); // software debounce
        if (digitalRead(button) == HIGH) {
            // if the switch is HIGH, ie. pushed down - change the lights!
            delay(15000); // wait for 15 seconds

Leave a Reply

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

You are commenting using your 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