Test PS3 - Dribbler
Dependencies: SerialArduino RCJESC
Diff: main.cpp
- Revision:
- 0:97e795fb633f
diff -r 000000000000 -r 97e795fb633f main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Jun 17 02:54:39 2022 +0000 @@ -0,0 +1,63 @@ + + +#if 1 +#include "mbed.h" +#include "esc.h" +#include "SerialArduino.h" + +RCJESC esc(PC_9); +DigitalIn myb(PC_3); +DigitalOut led(LED1); +SerialArduino mini(A0, A1, 115200); + +uint8_t h1,h2; +bool b[12]= {}; +uint8_t st[4]= {}; +uint8_t tr[2]= {}; + +void PS3get(bool flag_PS3print); + +int main() +{ + esc.setspeed(0.0); + thread_sleep_for(1200); + + while (1) { + PS3get(false); +// if(myb) esc.setspeed(0.7); +// else esc.setspeed(0.0); +// led = myb; + if(b[2]) esc.setspeed(0.7); + else esc.setspeed(0.0); + led = b[2]; + } +} + +void PS3get(bool flag_PS3print) +{ + h1 = mini.getHedder1(); + h2 = mini.getHedder2(); + for(int i=0; i<12; i++) { + b[i] = mini.getButton(i); + } + for(int i=0; i<2; i++) { + tr[i] = mini.getTrigger(i); + } + for(int i=0; i<4; i++) { + st[i] = mini.getStick(i); + } + if (flag_PS3print) { + for(int i=0; i<12; i++) printf("%d ",b[i]); + printf("|"); + for(int i=0; i<2; i++) printf("%3d ",tr[i]); + printf("|"); + for(int i=0; i<4; i++) printf("%3d ",st[i]); + if(mini.getState()) printf("ok"); + else printf("bad"); + printf("\r\n"); + } else { + mini.getState(); + } +} + +#endif \ No newline at end of file