Irfan Refai
/
EMG_check_or
Irfan EMG Check
Fork of EMG_check by
main.cpp@2:049f61b9ebcb, 2016-09-23 (annotated)
- Committer:
- irfanmoh
- Date:
- Fri Sep 23 14:33:43 2016 +0000
- Revision:
- 2:049f61b9ebcb
- Parent:
- 1:6605db01437d
revision switch on character;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sivuu | 0:b7cb5d3978b5 | 1 | #include "mbed.h" |
sivuu | 0:b7cb5d3978b5 | 2 | |
sivuu | 0:b7cb5d3978b5 | 3 | DigitalOut led(LED_RED); |
sivuu | 0:b7cb5d3978b5 | 4 | DigitalOut led2(LED_BLUE); |
sivuu | 0:b7cb5d3978b5 | 5 | DigitalIn sw2(SW2); |
irfanmoh | 1:6605db01437d | 6 | InterruptIn sw3(SW3); |
sivuu | 0:b7cb5d3978b5 | 7 | Serial pc(USBTX, USBRX); |
irfanmoh | 1:6605db01437d | 8 | int n = 0; |
irfanmoh | 1:6605db01437d | 9 | |
irfanmoh | 1:6605db01437d | 10 | |
irfanmoh | 1:6605db01437d | 11 | void SwitchN() { |
irfanmoh | 1:6605db01437d | 12 | n++; |
irfanmoh | 1:6605db01437d | 13 | } |
sivuu | 0:b7cb5d3978b5 | 14 | |
sivuu | 0:b7cb5d3978b5 | 15 | int main() |
sivuu | 0:b7cb5d3978b5 | 16 | { |
sivuu | 0:b7cb5d3978b5 | 17 | pc.baud(115200); |
irfanmoh | 1:6605db01437d | 18 | |
irfanmoh | 2:049f61b9ebcb | 19 | |
sivuu | 0:b7cb5d3978b5 | 20 | |
sivuu | 0:b7cb5d3978b5 | 21 | while (true) { |
irfanmoh | 2:049f61b9ebcb | 22 | sw3.fall(&SwitchN); |
irfanmoh | 2:049f61b9ebcb | 23 | |
irfanmoh | 2:049f61b9ebcb | 24 | char c = pc.getc(); |
sivuu | 0:b7cb5d3978b5 | 25 | |
irfanmoh | 2:049f61b9ebcb | 26 | |
irfanmoh | 2:049f61b9ebcb | 27 | |
irfanmoh | 2:049f61b9ebcb | 28 | |
sivuu | 0:b7cb5d3978b5 | 29 | |
irfanmoh | 2:049f61b9ebcb | 30 | switch (c) |
irfanmoh | 2:049f61b9ebcb | 31 | { |
irfanmoh | 2:049f61b9ebcb | 32 | case 's': |
irfanmoh | 2:049f61b9ebcb | 33 | { |
irfanmoh | 2:049f61b9ebcb | 34 | if (n%2 == 0) |
irfanmoh | 2:049f61b9ebcb | 35 | { |
irfanmoh | 2:049f61b9ebcb | 36 | pc.printf("up \n\r"); |
irfanmoh | 2:049f61b9ebcb | 37 | } |
irfanmoh | 2:049f61b9ebcb | 38 | else |
irfanmoh | 2:049f61b9ebcb | 39 | { |
irfanmoh | 2:049f61b9ebcb | 40 | pc.printf("right \n\r"); |
sivuu | 0:b7cb5d3978b5 | 41 | } |
irfanmoh | 2:049f61b9ebcb | 42 | break; |
irfanmoh | 2:049f61b9ebcb | 43 | } |
irfanmoh | 2:049f61b9ebcb | 44 | case 'd': |
irfanmoh | 2:049f61b9ebcb | 45 | { |
irfanmoh | 2:049f61b9ebcb | 46 | if (n%2 == 0) |
irfanmoh | 2:049f61b9ebcb | 47 | { |
irfanmoh | 2:049f61b9ebcb | 48 | pc.printf("down \n\r"); } |
irfanmoh | 2:049f61b9ebcb | 49 | else |
irfanmoh | 2:049f61b9ebcb | 50 | { |
irfanmoh | 2:049f61b9ebcb | 51 | pc.printf("left \n\r"); |
irfanmoh | 2:049f61b9ebcb | 52 | } |
irfanmoh | 2:049f61b9ebcb | 53 | break; |
sivuu | 0:b7cb5d3978b5 | 54 | |
irfanmoh | 2:049f61b9ebcb | 55 | } |
irfanmoh | 2:049f61b9ebcb | 56 | } |
irfanmoh | 2:049f61b9ebcb | 57 | |
sivuu | 0:b7cb5d3978b5 | 58 | } |
sivuu | 0:b7cb5d3978b5 | 59 | } |