lab 2 part2
Dependencies: mbed
Fork of lab2_part2 by
Diff: main.cpp
- Revision:
- 0:ab4dd338b42b
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Sep 03 19:48:24 2014 +0000 @@ -0,0 +1,44 @@ +#include "mbed.h" + +Serial pc(USBTX, USBRX); + +int main() { + + pc.baud(921600); //set the baud rate to 921600 + float x2,y2; //initializes variables + AnalogIn an(p15); //creates an analog in on p15 + BusOut boom(LED1, LED2, LED3, LED4); // creates a bus that's outputs are the 4 LEDS on the mbed + + while(1) + { + x2=an.read(); //reads in the value of the input on p15 in range of 0.0 to 1.0 + y2=x2*3.3; //the voltage is max Voltage multiplied by the read in value. + printf("The analog data value is %f, and the associated voltage is %f\n",x2, y2); + + //if statements set the value of the bus based off the value read in from the analog + //value boom is set to is based off of binary, a 1 sent to the LED turns it on. + if(x2<=.2) + boom=0; //no LEDs are on + + if((x2>.2)&&(x2<=.4)) + boom=1; // turns on one light + + + if((x2>.4)&&(x2<=.6)) + boom=3; //turns on two lights + + + if((x2>.6)&&(x2<=.8)) + boom=7; // turns on three lights + + if((x2>.8)&&(x2<=1.0)) + boom=15; //turns on all four lights + + wait(.5); + } + + + + + + } \ No newline at end of file