Cecilia Schneider
/
schneider_hw_2
Uses the analog input value to control how many LEDs are on
Diff: main.cpp
- Revision:
- 0:7576b8ed15e8
- Child:
- 1:1e1de02b30cc
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Sep 25 02:04:21 2018 +0000 @@ -0,0 +1,61 @@ +// Cecilia Schneider, OCE 360, September 24,2018 +// HW #2, exercise 2, Analog I/O +// Use the analog input value to control how many LEDs are on +#include "mbed.h" + +Serial pc(USBTX, USBRX); +AnalogIn Ain(p20); //Potentiometer input is on pin 20, this value will determine which LEDs are on +DigitalOut rled(p5); //LEDs will light based on the analog input +DigitalOut yled(p7); +DigitalOut gled(p9); +DigitalOut bled(p11); +float ADCdata; + +int main() { + pc.printf("ADC Data Values... \n\r"); + while (1) { + ADCdata = Ain; + wait (0.5); //Updates every half second + if(Ain <= 0.2f) { //if the analog input is less than or equal to 0.2 all LEDs will be off + pc.printf("%3.2f",ADCdata); //displays analog input value + pc.printf(" All LEDs OFF. Voltage at pin 20: "); //displays which LEDs should be lit + pc.printf("%3.2f \n\r", ADCdata*3.3); //displays actual voltage at pin 20 + rled = 0; + yled = 0; + gled = 0; + bled = 0; + } else if(0.2f<Ain, Ain<=0.4f) { //if Ain is between 0.2 and 0.4 only the red LED will be on + pc.printf("%3.2f",ADCdata); //displays analog input value + pc.printf(" Red LED ON. Voltage at pin 20: "); //displays which LEDs should be lit + pc.printf("%3.2f \n\r", ADCdata*3.3); //displays actual voltage at pin 20 + rled = 1; + yled = 0; + gled = 0; + bled = 0; + } else if(0.4f<Ain, Ain<=0.6f) { //if Ain is between 0.4 and 0.6 the red and yellow LEDs will be on + pc.printf("%3.2f",ADCdata); //displays analog input value + pc.printf(" Red and yellow LEDs ON. Voltage at pin 20: "); //displays which LEDs should be lit + pc.printf("%3.2f \n\r", ADCdata*3.3); //displays actual voltage at pin 20 + rled = 1; + yled = 1; + gled = 0; + bled = 0; + } else if(0.6f<Ain, Ain<=0.8f) { //if Ain is between 0.6 and 0.8 the red yellow and green LEDs will be on + pc.printf("%3.2f",ADCdata); //displays analog input value + pc.printf(" Red, yellow, and green LEDs ON. Voltage at pin 20: "); //displays which LEDs should be lit + pc.printf("%3.2f \n\r", ADCdata*3.3); //displays actual voltage at pin 20 + rled = 1; + yled = 1; + gled = 1; + bled = 0; + } else if(0.8f<Ain, Ain<=1.0f) { //if Ain is greater than 0.8 all LEDs will be on + pc.printf("%3.2f",ADCdata); //displays analog input value + pc.printf(" Red, yellow, green and blue LEDs ON. Voltage at pin 20: "); //displays which LEDs should be lit + pc.printf("%3.2f \n\r", ADCdata*3.3); //displays actual voltage at pin 20 + rled = 1; + yled = 1; + gled = 1; + bled = 1; + } + } +} \ No newline at end of file