Lingxuan Zeng
/
masterboard
works with chairdetect and listening
Diff: main.cpp
- Revision:
- 0:ed2c77b37f59
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri May 03 11:15:21 2013 +0000 @@ -0,0 +1,100 @@ +#include "mbed.h" +#include "TextLCD.h" + +Timer t; + +DigitalOut led1(LED_BLUE); +DigitalOut led2(LED_RED); +TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7 + +Serial wire(PTD3,PTD2); +Serial xbee2(PTC4, PTC3); +DigitalOut rst2(PTC5); + + + +int main() +{ + + //initiating lcd and xbee reset + + lcd.cls(); + lcd.locate(0,0); + lcd.printf("starting\n"); + rst2 = 0; + wait_ms(1); + rst2 = 1; + wait_ms(1); + + + char alast = 0; + char a = 0; + + char typingflag; + + int typingtime; + + float timesitting; + + led1 = 1; + led2 = 1; + typingflag=0; + typingtime=0; + + + while(1) { + if (xbee2.readable() && wire.readable()) { + + a = xbee2.getc(); + lcd.putc(a); + lcd.locate(0,1); + lcd.printf("t=%f",t.read()); + + typingflag=wire.getc(); + lcd.locate(2,0); + lcd.printf("%d", (int) typingflag); + + if((int) typingflag == 1) + { + led1 = 0; + typingtime++; + wait(0.5); + } + + + if (a != alast) { + if (a == '1') { + t.start(); + led1 = 0; + } + else { + // if (alast == 1) { + + t.stop(); + led2 = 0; + timesitting = t.read(); + lcd.cls(); + lcd.locate(0,0); + lcd.printf("%d", typingtime); + lcd.locate(0,1); + lcd.printf("%f",timesitting); + + + t.reset(); + typingtime = 0; + wait(3); + } // terminate else + } // terminate if (a != alast) + + } // terminate if (xbee2.readable() && wire.readable()) + + + + + alast = a; + wait(0.8); + lcd.cls(); + led1 = 1; + led2 = 1; + } + }