Xiaofei Qiu
/
EasyVR3_LED
EasyVR3_LED
main.cpp@0:13b922a701d4, 2015-10-22 (annotated)
- Committer:
- Xiaofei
- Date:
- Thu Oct 22 18:58:41 2015 +0000
- Revision:
- 0:13b922a701d4
EasyVR3 LAB
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Xiaofei | 0:13b922a701d4 | 1 | #include "mbed.h" |
Xiaofei | 0:13b922a701d4 | 2 | #include "EasyVR.h" |
Xiaofei | 0:13b922a701d4 | 3 | |
Xiaofei | 0:13b922a701d4 | 4 | DigitalOut led1(LED1); |
Xiaofei | 0:13b922a701d4 | 5 | DigitalOut led4(LED4); |
Xiaofei | 0:13b922a701d4 | 6 | |
Xiaofei | 0:13b922a701d4 | 7 | EasyVR VR(p13, p14); // tx, rx |
Xiaofei | 0:13b922a701d4 | 8 | Serial pc(USBTX,USBRX); |
Xiaofei | 0:13b922a701d4 | 9 | |
Xiaofei | 0:13b922a701d4 | 10 | PwmOut red(p21); |
Xiaofei | 0:13b922a701d4 | 11 | PwmOut blue(p22); |
Xiaofei | 0:13b922a701d4 | 12 | PwmOut green(p23); |
Xiaofei | 0:13b922a701d4 | 13 | |
Xiaofei | 0:13b922a701d4 | 14 | void ledDance(); |
Xiaofei | 0:13b922a701d4 | 15 | |
Xiaofei | 0:13b922a701d4 | 16 | int main() { |
Xiaofei | 0:13b922a701d4 | 17 | char buffer=0; |
Xiaofei | 0:13b922a701d4 | 18 | |
Xiaofei | 0:13b922a701d4 | 19 | if(VR.awake()) //wake up device - needs more work and a timeout |
Xiaofei | 0:13b922a701d4 | 20 | { |
Xiaofei | 0:13b922a701d4 | 21 | led1 = 1; |
Xiaofei | 0:13b922a701d4 | 22 | } |
Xiaofei | 0:13b922a701d4 | 23 | |
Xiaofei | 0:13b922a701d4 | 24 | while (1) |
Xiaofei | 0:13b922a701d4 | 25 | { |
Xiaofei | 0:13b922a701d4 | 26 | VR.sendCmd(CMD_RECOG_SI); // Start Recognition |
Xiaofei | 0:13b922a701d4 | 27 | VR.sendArg(1); // Use Wordset 3 - the numbers 0..10 |
Xiaofei | 0:13b922a701d4 | 28 | |
Xiaofei | 0:13b922a701d4 | 29 | buffer = VR.recv(); // Receive a byte from easyVR |
Xiaofei | 0:13b922a701d4 | 30 | |
Xiaofei | 0:13b922a701d4 | 31 | if(buffer == CMD_SLEEP) // If easyVR is sleeping |
Xiaofei | 0:13b922a701d4 | 32 | { |
Xiaofei | 0:13b922a701d4 | 33 | VR.sendCmd(' '); // Send blanck to activate it |
Xiaofei | 0:13b922a701d4 | 34 | } |
Xiaofei | 0:13b922a701d4 | 35 | else |
Xiaofei | 0:13b922a701d4 | 36 | { |
Xiaofei | 0:13b922a701d4 | 37 | VR.decrypt(&buffer); // If not sleeping, decrtpt received message |
Xiaofei | 0:13b922a701d4 | 38 | pc.printf("%d\n",buffer); |
Xiaofei | 0:13b922a701d4 | 39 | } |
Xiaofei | 0:13b922a701d4 | 40 | |
Xiaofei | 0:13b922a701d4 | 41 | // if command is taken by easyVR, the LED4 will toggle |
Xiaofei | 0:13b922a701d4 | 42 | if (buffer==7) {red = 0; green = 1; blue = 0;led4=!led4;} // hello |
Xiaofei | 0:13b922a701d4 | 43 | if (buffer==6) {red = 0; green = 0; blue = 0;led4=!led4;} // stop or turn off |
Xiaofei | 0:13b922a701d4 | 44 | if (buffer==3) {led4=!led4;ledDance();} // run |
Xiaofei | 0:13b922a701d4 | 45 | if (buffer==7) led4=!led4; |
Xiaofei | 0:13b922a701d4 | 46 | wait(0.1); |
Xiaofei | 0:13b922a701d4 | 47 | } |
Xiaofei | 0:13b922a701d4 | 48 | } |
Xiaofei | 0:13b922a701d4 | 49 | |
Xiaofei | 0:13b922a701d4 | 50 | void ledDance() |
Xiaofei | 0:13b922a701d4 | 51 | { |
Xiaofei | 0:13b922a701d4 | 52 | for(int i=0;i<5000;i++) |
Xiaofei | 0:13b922a701d4 | 53 | { |
Xiaofei | 0:13b922a701d4 | 54 | red = !green; |
Xiaofei | 0:13b922a701d4 | 55 | green = !blue; |
Xiaofei | 0:13b922a701d4 | 56 | blue = !red; |
Xiaofei | 0:13b922a701d4 | 57 | wait(0.001); |
Xiaofei | 0:13b922a701d4 | 58 | } |
Xiaofei | 0:13b922a701d4 | 59 | red = 1; |
Xiaofei | 0:13b922a701d4 | 60 | green = 0; |
Xiaofei | 0:13b922a701d4 | 61 | blue = 0; |
Xiaofei | 0:13b922a701d4 | 62 | |
Xiaofei | 0:13b922a701d4 | 63 | } |