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 LED (red or

ID: 3572326 • Letter: W

Question

write a C program that:

Use the solderless breadboard to wire up one LED (red or green, your choice) to pin 5. Include a current limiting resistor and the ground connection. Write a program that: Does 1000 blinks with where the LED is on for 1 ms and off for 4 ms. Does 1000 blinks with where the LED is on for 2 ms and off for 3 ms. Does 1000 blinks with where the LED is on for 3 ms and off for 1 ms. Does 1000 blinks with where the LED is on for 4 ms and off for 1 ms. The sequence cycles repeatedly. One loop will last 20 seconds (4 * 5 ms * 1000 = 20 s). Note that the LED will be blinking on and off so fast that you will not see individual blinks with your eye. Instead, you will see many periods averaged together. Again, you can use the Arduino delay () function or you can use the improved timer approach as described in class. Obviously, you will need to make good use of loops to implement this program. What do you see happening with the LED as the on/off times change?

Explanation / Answer

Hi,

I can see small mistake in the point 3. There the total on, off time is 4 ms.

But I am considering ON time is 3ms and OFF time 2 ms.

// Connect Green LED to pin 5
const int MyLED = 5;

// the setup function is one time initialization function runs once when the board is reset or powered up
void setup() {
// initialize digital pin 5 as an output.
pinMode(MyLED, OUTPUT);
}

// This loop function runs indefinitely
void loop() {

// loop 1: 1000 blinks with LED ON Time = 1ms, OFF Time = 4ms
for (int i=1; i <= 1000; i++){
digitalWrite(MyLED, HIGH); // turn the LED on by setting the voltage HIGH
delay(1); // ON the LED for 1ms
digitalWrite(MyLED, LOW); // turn the LED off by setting the voltage LOW
delay(4); // OFF the LED for 4ms
}

// loop 2: 1000 blinks with LED ON Time = 2ms, OFF Time = 3ms
for (int i=1; i <= 1000; i++){
digitalWrite(MyLED, HIGH); // turn the LED on by setting the voltage HIGH
delay(2); // ON the LED for 1ms
digitalWrite(MyLED, LOW); // turn the LED off by setting the voltage LOW
delay(3); // OFF the LED for 4ms
}

// loop 3: 1000 blinks with LED ON Time = 3ms, OFF Time = 2ms
for (int i=1; i <= 1000; i++){
digitalWrite(MyLED, HIGH); // turn the LED on by setting the voltage HIGH
delay(3); // ON the LED for 3ms
digitalWrite(MyLED, LOW); // turn the LED off by setting the voltage LOW
delay(2); // OFF the LED for 2ms
}

// loop 3: 1000 blinks with LED ON Time = 4ms, OFF Time = 1ms
for (int i=1; i <= 1000; i++){
digitalWrite(MyLED, HIGH); // turn the LED on by setting the voltage HIGH
delay(4); // ON the LED for 4ms
digitalWrite(MyLED, LOW); // turn the LED off by setting the voltage LOW
delay(1); // OFF the LED for 1ms
}
  
} // major loop end