Test PS3 - Dribbler
Dependencies: SerialArduino RCJESC
main.cpp@0:97e795fb633f, 2022-06-17 (annotated)
- Committer:
- piroro4560
- Date:
- Fri Jun 17 02:54:39 2022 +0000
- Revision:
- 0:97e795fb633f
Test PS3 - Dribbler
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
piroro4560 | 0:97e795fb633f | 1 | |
piroro4560 | 0:97e795fb633f | 2 | |
piroro4560 | 0:97e795fb633f | 3 | #if 1 |
piroro4560 | 0:97e795fb633f | 4 | #include "mbed.h" |
piroro4560 | 0:97e795fb633f | 5 | #include "esc.h" |
piroro4560 | 0:97e795fb633f | 6 | #include "SerialArduino.h" |
piroro4560 | 0:97e795fb633f | 7 | |
piroro4560 | 0:97e795fb633f | 8 | RCJESC esc(PC_9); |
piroro4560 | 0:97e795fb633f | 9 | DigitalIn myb(PC_3); |
piroro4560 | 0:97e795fb633f | 10 | DigitalOut led(LED1); |
piroro4560 | 0:97e795fb633f | 11 | SerialArduino mini(A0, A1, 115200); |
piroro4560 | 0:97e795fb633f | 12 | |
piroro4560 | 0:97e795fb633f | 13 | uint8_t h1,h2; |
piroro4560 | 0:97e795fb633f | 14 | bool b[12]= {}; |
piroro4560 | 0:97e795fb633f | 15 | uint8_t st[4]= {}; |
piroro4560 | 0:97e795fb633f | 16 | uint8_t tr[2]= {}; |
piroro4560 | 0:97e795fb633f | 17 | |
piroro4560 | 0:97e795fb633f | 18 | void PS3get(bool flag_PS3print); |
piroro4560 | 0:97e795fb633f | 19 | |
piroro4560 | 0:97e795fb633f | 20 | int main() |
piroro4560 | 0:97e795fb633f | 21 | { |
piroro4560 | 0:97e795fb633f | 22 | esc.setspeed(0.0); |
piroro4560 | 0:97e795fb633f | 23 | thread_sleep_for(1200); |
piroro4560 | 0:97e795fb633f | 24 | |
piroro4560 | 0:97e795fb633f | 25 | while (1) { |
piroro4560 | 0:97e795fb633f | 26 | PS3get(false); |
piroro4560 | 0:97e795fb633f | 27 | // if(myb) esc.setspeed(0.7); |
piroro4560 | 0:97e795fb633f | 28 | // else esc.setspeed(0.0); |
piroro4560 | 0:97e795fb633f | 29 | // led = myb; |
piroro4560 | 0:97e795fb633f | 30 | if(b[2]) esc.setspeed(0.7); |
piroro4560 | 0:97e795fb633f | 31 | else esc.setspeed(0.0); |
piroro4560 | 0:97e795fb633f | 32 | led = b[2]; |
piroro4560 | 0:97e795fb633f | 33 | } |
piroro4560 | 0:97e795fb633f | 34 | } |
piroro4560 | 0:97e795fb633f | 35 | |
piroro4560 | 0:97e795fb633f | 36 | void PS3get(bool flag_PS3print) |
piroro4560 | 0:97e795fb633f | 37 | { |
piroro4560 | 0:97e795fb633f | 38 | h1 = mini.getHedder1(); |
piroro4560 | 0:97e795fb633f | 39 | h2 = mini.getHedder2(); |
piroro4560 | 0:97e795fb633f | 40 | for(int i=0; i<12; i++) { |
piroro4560 | 0:97e795fb633f | 41 | b[i] = mini.getButton(i); |
piroro4560 | 0:97e795fb633f | 42 | } |
piroro4560 | 0:97e795fb633f | 43 | for(int i=0; i<2; i++) { |
piroro4560 | 0:97e795fb633f | 44 | tr[i] = mini.getTrigger(i); |
piroro4560 | 0:97e795fb633f | 45 | } |
piroro4560 | 0:97e795fb633f | 46 | for(int i=0; i<4; i++) { |
piroro4560 | 0:97e795fb633f | 47 | st[i] = mini.getStick(i); |
piroro4560 | 0:97e795fb633f | 48 | } |
piroro4560 | 0:97e795fb633f | 49 | if (flag_PS3print) { |
piroro4560 | 0:97e795fb633f | 50 | for(int i=0; i<12; i++) printf("%d ",b[i]); |
piroro4560 | 0:97e795fb633f | 51 | printf("|"); |
piroro4560 | 0:97e795fb633f | 52 | for(int i=0; i<2; i++) printf("%3d ",tr[i]); |
piroro4560 | 0:97e795fb633f | 53 | printf("|"); |
piroro4560 | 0:97e795fb633f | 54 | for(int i=0; i<4; i++) printf("%3d ",st[i]); |
piroro4560 | 0:97e795fb633f | 55 | if(mini.getState()) printf("ok"); |
piroro4560 | 0:97e795fb633f | 56 | else printf("bad"); |
piroro4560 | 0:97e795fb633f | 57 | printf("\r\n"); |
piroro4560 | 0:97e795fb633f | 58 | } else { |
piroro4560 | 0:97e795fb633f | 59 | mini.getState(); |
piroro4560 | 0:97e795fb633f | 60 | } |
piroro4560 | 0:97e795fb633f | 61 | } |
piroro4560 | 0:97e795fb633f | 62 | |
piroro4560 | 0:97e795fb633f | 63 | #endif |