I have a starter code outline, and a track list I am trying to achieve which is a laundry list of functions and displays and am having the worst time of my life:
Task List:
• Add code to the setup function to configure the serial port
• Add code to the loop function to cross fade the LEDS. Cross fade means that one LED gets brighter as the other LED becomes dimmer.
• Add code to the update_leds function
• Add code to the display_debug_info function
• Serially transmit the following data, displaying it in the Serial Monitor
• Display the analog write values
• Display the duty cycle percentage values
• Display the pin voltage values, using at least 2 decimal places
• Display the currents, using at least 3 decimal places
• Add code to the performCalculations function
• Calculate the duty cycle percentage
• Calculate the pin voltage values. You will need to write a mathematical equation to calculate the pin voltage, based on the analog write values. 255 represents a 100% duty cycle, which is 5V. 0 represents a 0% duty cycle, which is 0V.
• Calculate the current in each LED circuit.
Here is the starter code:
// pwm pins
const int redPin = 9; // red LED, connected to digital pin 9
const int yellowPin = 10; // yellow LED, connected to digital pin 10
// Analog Write Variables
unsigned char redAnalogValue;
unsigned char yellowAnalogValue;
// Control variables
int loopCount;
int wait = 50; // 50ms (.05 second) delay; shorten for faster fades
void setup()
{
/** add code to configure the serial port
*
- Note: it is not necessary to set the pinMode for pins using analogWrite
*/
}
void display_debug_info(void)
{
/** add code here
*
- write the value of loopCount, red duty cycle, and the yellow
- duty cycle to the serial port. Neatly label and format
- the output.
- If you want to space over a tab: Serial.print("\t");
*/
}
void performCalculations(void){
/** add code here to perform all required
- voltage, current, and duty % calculations
*/
}
void update_leds(void)
{
/** add code here
*
- use the analogWrite function to update the led brightness
*/
delay(wait);
} // end function update_leds()
void loop()
{
/* create a while loop that runs 256 times
- the red led should become dimmer
- the yellow led should become brighter
- set redAnalogValue to 255
- set yellowAnalogValue to 0
- set loopCount to 0
- The loop's boolean test condition should be
- true 256 times. The loopCount variable
- controls how many times the loop executes
- while ( boolean test condition is true )
- subtract 1 from the red analog value
- add 1 to the yellow analog value
- write the updated values to the leds
- display debugging information
- update the loop count
*/
/**
- write a for loop that runs 256 times
- the red led should become brighter
- the yellow led should become dimmer
- set redAnalogValue to 0
- set yellowAnalogValue to 255
- set loopCount to 0
- while ( boolean test condition is true )
- add 1 to the red analog value
- subtract 1 from the yellow analog value
- write the updated values to the leds
- display debugging information
- update the loop count
*/
}