0% found this document useful (0 votes)
31 views4 pages

Muhammad Ibrahim Calab1

The code defines a setup function that configures 12 pins as outputs to control 4 sets of traffic lights. The loop function then sequentially sets one set of lights to green while setting the others to red, pausing for 1 second between each change. This creates a basic simulated traffic light sequence.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views4 pages

Muhammad Ibrahim Calab1

The code defines a setup function that configures 12 pins as outputs to control 4 sets of traffic lights. The loop function then sequentially sets one set of lights to green while setting the others to red, pausing for 1 second between each change. This creates a basic simulated traffic light sequence.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

12407 Muhammad Ibrahim

CA Lab 1

Q1:

Code:

void setup() {

// Set the traffic light pins as output

pinMode(A0, OUTPUT); // green 1

pinMode(A1, OUTPUT); // yellow 1

pinMode(A2, OUTPUT);// red 1

pinMode(A5, OUTPUT);//green 2

pinMode(A4, OUTPUT);//yellow 2

pinMode(A3, OUTPUT);//red 2

pinMode(0, OUTPUT);// red 3

pinMode(1, OUTPUT);// yellow 3

pinMode(2, OUTPUT);// green 3

pinMode(11, OUTPUT);// green 4

pinMode(12, OUTPUT);// yellow 4

pinMode(13, OUTPUT);// red 4

void loop() {

// Set the first traffic light to green and the rest to red

digitalWrite(A0, HIGH);

digitalWrite(A1, LOW);

digitalWrite(A2, LOW);

digitalWrite(A5, LOW);

digitalWrite(A4, LOW);

digitalWrite(A3, HIGH);

digitalWrite(2, LOW);
digitalWrite(1, LOW);

digitalWrite(0, HIGH);

digitalWrite(11, LOW);

digitalWrite(12, LOW);

digitalWrite(13, HIGH);

delay(1000); // Wait for 1 second

// Set the second traffic light to green and the rest to red

digitalWrite(A0, LOW);

digitalWrite(A1, LOW);

digitalWrite(A2, HIGH);

digitalWrite(A5, HIGH);

digitalWrite(A4, LOW);

digitalWrite(A3, LOW);

digitalWrite(2, LOW);

digitalWrite(1, LOW);

digitalWrite(0, HIGH);

digitalWrite(11, LOW);

digitalWrite(12, LOW);

digitalWrite(13, HIGH);

delay(1000); // Wait for 1 second

// Set the third traffic light to green and the rest to red

digitalWrite(A0, LOW);

digitalWrite(A1, LOW);

digitalWrite(A2, HIGH);

digitalWrite(A5, LOW);
digitalWrite(A4, LOW);

digitalWrite(A3, HIGH);

digitalWrite(2, HIGH);

digitalWrite(1, LOW);

digitalWrite(0, LOW);

digitalWrite(11, LOW);

digitalWrite(12, LOW);

digitalWrite(13, HIGH);

delay(1000); // Wait for 1 second

// Set the fourth traffic light to green and the rest to red

digitalWrite(A0, LOW);

digitalWrite(A1, LOW);

digitalWrite(A2, HIGH);

digitalWrite(A5, LOW);

digitalWrite(A4, LOW);

digitalWrite(A3, HIGH);

digitalWrite(2, LOW);

digitalWrite(1, LOW);

digitalWrite(0, HIGH);

digitalWrite(11, HIGH);

digitalWrite(12, LOW);

digitalWrite(13, LOW);

delay(1000); // Wait for 1 second

You might also like