lab 2 part2

Dependencies:   mbed

Fork of lab2_part2 by Rebecca Greenberg

Committer:
m162568
Date:
Wed Sep 03 19:48:24 2014 +0000
Revision:
0:ab4dd338b42b
lab2 part2;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
m162568 0:ab4dd338b42b 1 #include "mbed.h"
m162568 0:ab4dd338b42b 2
m162568 0:ab4dd338b42b 3 Serial pc(USBTX, USBRX);
m162568 0:ab4dd338b42b 4
m162568 0:ab4dd338b42b 5 int main() {
m162568 0:ab4dd338b42b 6
m162568 0:ab4dd338b42b 7 pc.baud(921600); //set the baud rate to 921600
m162568 0:ab4dd338b42b 8 float x2,y2; //initializes variables
m162568 0:ab4dd338b42b 9 AnalogIn an(p15); //creates an analog in on p15
m162568 0:ab4dd338b42b 10 BusOut boom(LED1, LED2, LED3, LED4); // creates a bus that's outputs are the 4 LEDS on the mbed
m162568 0:ab4dd338b42b 11
m162568 0:ab4dd338b42b 12 while(1)
m162568 0:ab4dd338b42b 13 {
m162568 0:ab4dd338b42b 14 x2=an.read(); //reads in the value of the input on p15 in range of 0.0 to 1.0
m162568 0:ab4dd338b42b 15 y2=x2*3.3; //the voltage is max Voltage multiplied by the read in value.
m162568 0:ab4dd338b42b 16 printf("The analog data value is %f, and the associated voltage is %f\n",x2, y2);
m162568 0:ab4dd338b42b 17
m162568 0:ab4dd338b42b 18 //if statements set the value of the bus based off the value read in from the analog
m162568 0:ab4dd338b42b 19 //value boom is set to is based off of binary, a 1 sent to the LED turns it on.
m162568 0:ab4dd338b42b 20 if(x2<=.2)
m162568 0:ab4dd338b42b 21 boom=0; //no LEDs are on
m162568 0:ab4dd338b42b 22
m162568 0:ab4dd338b42b 23 if((x2>.2)&&(x2<=.4))
m162568 0:ab4dd338b42b 24 boom=1; // turns on one light
m162568 0:ab4dd338b42b 25
m162568 0:ab4dd338b42b 26
m162568 0:ab4dd338b42b 27 if((x2>.4)&&(x2<=.6))
m162568 0:ab4dd338b42b 28 boom=3; //turns on two lights
m162568 0:ab4dd338b42b 29
m162568 0:ab4dd338b42b 30
m162568 0:ab4dd338b42b 31 if((x2>.6)&&(x2<=.8))
m162568 0:ab4dd338b42b 32 boom=7; // turns on three lights
m162568 0:ab4dd338b42b 33
m162568 0:ab4dd338b42b 34 if((x2>.8)&&(x2<=1.0))
m162568 0:ab4dd338b42b 35 boom=15; //turns on all four lights
m162568 0:ab4dd338b42b 36
m162568 0:ab4dd338b42b 37 wait(.5);
m162568 0:ab4dd338b42b 38 }
m162568 0:ab4dd338b42b 39
m162568 0:ab4dd338b42b 40
m162568 0:ab4dd338b42b 41
m162568 0:ab4dd338b42b 42
m162568 0:ab4dd338b42b 43
m162568 0:ab4dd338b42b 44 }