Problem 10 a Write a complete program to blink an LED connec

Problem 1.0 (a) Write a complete program to blink an LED connected to pin 9 on for 2 seconds and off for 1second, repeatedly. Also draw the schematic. (10 Points) Problem 1.0 (b) Write a complete program to simulate the traffic light controller for a two way street. Also draw the schematic. (15 Points)

Solution

Problem1.0(a)

Answer:


int led9 = 11;

// the setup routine runs once when you press reset:
void setup() {   
// initialize the digital pin as an output.
  
pinMode(led9, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  
{digitalWrite(led9, HIGH);
delay(2);//wait for two second
digitalWrite(led9, LOW);
delay(1);}// wait for a second
}

Problem1.0(b)

Answer:

int red = 13;
int yellow = 12;
int green = 11;
void setup()
{
pinMode(red,OUTPUT);
pinMode(yellow,OUTPUT);
pinMode(green,OUTPUT);
}
void loop(){
changeLights();
delay(15000);
}

void changeLights(){
// green off, yellow for 3 seconds
digitalWrite(green,HIGH);
digitalWrite(yellow,LOW);
delay(3000);

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

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

// turn off red and yellow, then turn on green
digitalWrite(yellow,LOW);
digitalWrite(red,LOW);
digitalWrite(green,HIGH);
}

 Problem 1.0 (a) Write a complete program to blink an LED connected to pin 9 on for 2 seconds and off for 1second, repeatedly. Also draw the schematic. (10 Poin

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site