Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C program. Ardunio code (write a code everywhere it says TODO) you are given code to make 1 LED blink, modify the code to make

C program. Ardunio code (write a code everywhere it says TODO)

you are given code to make 1 LED blink, modify the code to make 5 leds blink 1 at a time. Your code should: (1) keep track of the list of ledpins in an array (2) change the setup function to include setting up all LEDpins and use a loop (no repeated code) (2) implement the function OneAtATime() to turn on/off all the LEDs 1 at a time (3) The function you created to accomplish step (2) above should use a loop (no repeated code) */ /************************************************************* * Define Constants and Globals **************************************************************/ //TODO: change the variable ledPin to an int array ledPins to include 5 leds (pins 2 through 6) const int ledPin = 2; /**************************************************************** * Function Declarations ****************************************************************/ /* oneOnAtATime() * This function will step through the LEDs, * lighting only one at at time. */ void oneOnAtATime(int delayTime); /* Hardware connections: You'll need 5 LEDs, and 5 330 Ohm resistors(orange-orange-brown). - For each LED, connect the negative side (shorter leg) to a 330 Ohm resistor. - Connect the other side of the resistors to GND. - Connect the positive side (longer leg) of the LEDs to Arduino digital pins 2 through 6. */ /************************************************************** * The setup() function runs once when the sketch starts. * You'll use it for things you need to do first, or only once: **************************************************************/ void setup() { //TODO: include setting up all LEDpins and use a loop (no repeated code) pinMode(ledPin,OUTPUT); //setup the ledPin to be an OUTPUT pin } /******************************************************************* * After setup() finishes, the loop() function runs over and over * again, forever (or until you turn off or reset the Arduino). * This is usually where the bulk of your program lives: *************************************************************************/ void loop() { //TODO: replace the code below to call your function oneOnAtATime() int delayTime = 1000; digitalWrite(ledPin, HIGH); // turn LED on delay(delayTime); // pause to slow down digitalWrite(ledPin, LOW); // turn LED off delay(delayTime); // pause to slow down } /**************************************************************** * Function Definitions ****************************************************************/ /* oneOnAtATime() This function will step through the LEDs, lighting only one LED at at time. input arg: delayTime, is the number of miliseconds to wait between turning LEDs on/off */ void oneOnAtATime(int delayTime) { //TODO: implement the function oneOnAtATime() to turn on/off all the LEDs 1 at a time }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Antipatterns Avoiding The Pitfalls Of Database Programming

Authors: Bill Karwin

1st Edition

1680508989, 978-1680508987

More Books

Students also viewed these Databases questions

Question

How do Data Types perform data validation?

Answered: 1 week ago

Question

How does Referential Integrity work?

Answered: 1 week ago