Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Fork of lab2_part2 by
main.cpp
00001 #include "mbed.h" 00002 00003 Serial pc(USBTX, USBRX); 00004 00005 int main() { 00006 00007 pc.baud(921600); //set the baud rate to 921600 00008 float x2,y2; //initializes variables 00009 AnalogIn an(p15); //creates an analog in on p15 00010 BusOut boom(LED1, LED2, LED3, LED4); // creates a bus that's outputs are the 4 LEDS on the mbed 00011 00012 while(1) 00013 { 00014 x2=an.read(); //reads in the value of the input on p15 in range of 0.0 to 1.0 00015 y2=x2*3.3; //the voltage is max Voltage multiplied by the read in value. 00016 printf("The analog data value is %f, and the associated voltage is %f\n",x2, y2); 00017 00018 //if statements set the value of the bus based off the value read in from the analog 00019 //value boom is set to is based off of binary, a 1 sent to the LED turns it on. 00020 if(x2<=.2) 00021 boom=0; //no LEDs are on 00022 00023 if((x2>.2)&&(x2<=.4)) 00024 boom=1; // turns on one light 00025 00026 00027 if((x2>.4)&&(x2<=.6)) 00028 boom=3; //turns on two lights 00029 00030 00031 if((x2>.6)&&(x2<=.8)) 00032 boom=7; // turns on three lights 00033 00034 if((x2>.8)&&(x2<=1.0)) 00035 boom=15; //turns on all four lights 00036 00037 wait(.5); 00038 } 00039 00040 00041 00042 00043 00044 }
Generated on Sat Jul 16 2022 09:15:47 by
1.7.2
