Brady Dove
/
ResistiveSensors
lab
main.cpp@0:451fa025f45e, 2015-04-10 (annotated)
- Committer:
- bdove16
- Date:
- Fri Apr 10 01:04:29 2015 +0000
- Revision:
- 0:451fa025f45e
1111
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bdove16 | 0:451fa025f45e | 1 | #include "mbed.h" |
bdove16 | 0:451fa025f45e | 2 | |
bdove16 | 0:451fa025f45e | 3 | Serial s(USBTX, USBRX); //serial connection |
bdove16 | 0:451fa025f45e | 4 | AnalogIn photoIn(p20); //analog input pin20 and named PhotoIn |
bdove16 | 0:451fa025f45e | 5 | Timer t; //timer object for timestamp |
bdove16 | 0:451fa025f45e | 6 | |
bdove16 | 0:451fa025f45e | 7 | void setupSerial(void) |
bdove16 | 0:451fa025f45e | 8 | { |
bdove16 | 0:451fa025f45e | 9 | s.baud(19200); //sets the BaudRate |
bdove16 | 0:451fa025f45e | 10 | s.format(7,SerialBase::Even,1); //set DataBits, Parity, and StopBits |
bdove16 | 0:451fa025f45e | 11 | } |
bdove16 | 0:451fa025f45e | 12 | |
bdove16 | 0:451fa025f45e | 13 | int main(void) |
bdove16 | 0:451fa025f45e | 14 | { |
bdove16 | 0:451fa025f45e | 15 | setupSerial(); |
bdove16 | 0:451fa025f45e | 16 | |
bdove16 | 0:451fa025f45e | 17 | float time; //current time |
bdove16 | 0:451fa025f45e | 18 | float data; //current data |
bdove16 | 0:451fa025f45e | 19 | |
bdove16 | 0:451fa025f45e | 20 | |
bdove16 | 0:451fa025f45e | 21 | t.reset(); //resets timer |
bdove16 | 0:451fa025f45e | 22 | t.start(); //starts timer |
bdove16 | 0:451fa025f45e | 23 | |
bdove16 | 0:451fa025f45e | 24 | //Loop |
bdove16 | 0:451fa025f45e | 25 | int go = 1; |
bdove16 | 0:451fa025f45e | 26 | while(go==1) { |
bdove16 | 0:451fa025f45e | 27 | //Read data |
bdove16 | 0:451fa025f45e | 28 | data = photoIn.read(); |
bdove16 | 0:451fa025f45e | 29 | time= t.read(); |
bdove16 | 0:451fa025f45e | 30 | |
bdove16 | 0:451fa025f45e | 31 | //Print data to serial port |
bdove16 | 0:451fa025f45e | 32 | s.printf("%f,%f\n",time,data); |
bdove16 | 0:451fa025f45e | 33 | |
bdove16 | 0:451fa025f45e | 34 | wait(0.5); |
bdove16 | 0:451fa025f45e | 35 | } |
bdove16 | 0:451fa025f45e | 36 | } |
bdove16 | 0:451fa025f45e | 37 |