Jake Bonney
/
Assignment2
analog in leds show on pc terminal
Diff: Analog_IN.cpp
- Revision:
- 0:e6dc50dc9a0e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Analog_IN.cpp Thu Oct 05 23:57:44 2017 +0000 @@ -0,0 +1,62 @@ +#include "mbed.h" + +// Jake Bonney +// 10/2/17 +// OCE 360 +// Assignment 2: Analog I/O + +// continuously displays an analog input value to a terminal window +// use analog input to continuously control how many internal LEDs are on + +Serial pc(USBTX, USBRX); //links usb to pc terminal +DigitalOut myled1(LED1); //internal led +DigitalOut myled2(LED2); //internal led +DigitalOut myled3(LED3); //internal led +DigitalOut myled4(LED4); //internal led +AnalogIn Ain(p20); //Analog input +float ADCdata; + + int main() { + pc.printf("ADC Data Values... \n\r"); + while (1) { + ADCdata=Ain; + pc.printf("%f \n\r",ADCdata); // sends data to terminal + wait (0.5); + + // all leds off + if (Ain <= 0.2){ + myled1=0; + myled2=0; + myled3=0; + myled4=0; + } + // led1 is on + else if (0.2 < Ain <= 0.4){ + myled1=1; + myled2=0; + myled3=0; + myled4=0; + } + // led1, led2 on + else if (0.4 < Ain <= 0.6){ + myled1=1; + myled2=1; + myled3=0; + myled4=0; + } + // led 1,2,3 on + else if (0.6 < Ain <= 0.8){ + myled1=1; + myled2=1; + myled3=1; + myled4=0; + } + // all leds on + else if (0.8 < Ain <= 1){ + myled1=1; + myled2=1; + myled3=1; + myled4=1; + } + } + }