Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

write a C program that: Use the solderless breadboard to wire up one red LED and

ID: 3572328 • Letter: W

Question

write a C program that:

Use the solderless breadboard to wire up one red LED and one green LED to pins 5 and 6. Include current limiting resistors in series with the LEDs and don't forget to make the ground connection between the Arduino and the LEDs on the board. In writing the programs below, you can use the Arduino delay () function or you can use the improved timer approach as described in class. Of course, you must initialize everything in the setup portion of the program. Write a program that will blink the red LED 10 times (1 blink = on for 0.5 s and ofT for 0.5 s) and then blink green LED once (on for one second). The total sequence cycles repeatedly. Modify the program so that the red LED blinks 5 times (same on/off times) and the the green LED blinks 5 times (on for 0.25 seconds then off for 0.25 seconds). The sequence cycles repeatedly.

Explanation / Answer

1. The solution for first question is given as below

int RedledPin = 13;// red LED connected to digital pin 13

int GreenledPin=15;// green LED connected to digital pin 15

void setup()
{
  pinMode(RedledPin, OUTPUT);   // sets the digital pin as output for red led

   delay1(); //sets delay

pinMode(GreenledPin, OUTPUT); //sets digital pin as output for green led

delay2();

}

void delay1()
{ for(int i=0;i<10;i++1)

{
  digitalWrite(RedledPin, HIGH);   // sets the RED LED on
  delay(500);   // waits for a second
  digitalWrite(RedledPin, LOW);   // sets the RED LED off
  delay(500);

}}

void delay2()

{

digitalWrite(GreenledPin, HIGH);   // sets the GREEN LED on

}

2.The solution for the second question is as below:

int RedledPin = 13;// red LED connected to digital pin 13

int GreenledPin=15;// green LED connected to digital pin 15

void setup()
{
  pinMode(RedledPin, OUTPUT);   // sets the digital pin as output for red led

   delay1();   //sets delay

pinMode(GreenledPin, OUTPUT); //sets digital pin as output for green led

delay2();

}

void delay1()
{ for(int i=0;i<5;i++1)

{
  digitalWrite(RedledPin, HIGH);   // sets the RED LED on
  delay(500);   // waits for a second
  digitalWrite(RedledPin, LOW);   // sets the RED LED off
  delay(500);

}}

void delay2()

{ for(int i=0;i<5;i++)

digitalWrite(GreenledPin, HIGH);   // sets the GREEN LED on

delay(250);

digitalWrite(GreenledPin, LOW);

delay(250);

}