![](/media/cache/profiles/fe7ecc4de28b2c83c016b5c6c2acd826.jpg.50x50_q85.jpg)
HEBOCON machine
Dependencies: mbed Motorfader Servo WT2003M03
main.cpp@1:312b63cf250e, 2019-07-29 (annotated)
- Committer:
- abanum
- Date:
- Mon Jul 29 05:51:31 2019 +0000
- Revision:
- 1:312b63cf250e
- Parent:
- 0:a30ec7d94c3a
first pubrish
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
abanum | 0:a30ec7d94c3a | 1 | #include "mbed.h" |
abanum | 0:a30ec7d94c3a | 2 | #include "USBHostGamepad.h" |
abanum | 0:a30ec7d94c3a | 3 | #include "Servo.h" |
abanum | 1:312b63cf250e | 4 | #include "WT2003M03.h" |
abanum | 0:a30ec7d94c3a | 5 | #include "Motorfader.h" |
abanum | 0:a30ec7d94c3a | 6 | #include "stdio.h" |
abanum | 0:a30ec7d94c3a | 7 | #include "stdlib.h" |
abanum | 0:a30ec7d94c3a | 8 | #include "math.h" |
abanum | 0:a30ec7d94c3a | 9 | #include "string" |
abanum | 0:a30ec7d94c3a | 10 | |
abanum | 0:a30ec7d94c3a | 11 | #define SCREEN_WIDTH 128 |
abanum | 0:a30ec7d94c3a | 12 | #define SCREEN_HEIGHT 160 |
abanum | 0:a30ec7d94c3a | 13 | |
abanum | 0:a30ec7d94c3a | 14 | USBHostGamepad *pad; |
abanum | 0:a30ec7d94c3a | 15 | //Servo myservo1(D3); |
abanum | 0:a30ec7d94c3a | 16 | Servo tyre_R(D5); //TYRE RIGHT |
abanum | 0:a30ec7d94c3a | 17 | Servo tyre_L(D6); //TYRE LEFT |
abanum | 0:a30ec7d94c3a | 18 | //Servo myservo4(D4); |
abanum | 0:a30ec7d94c3a | 19 | PwmOut eye_R(PB_2); |
abanum | 0:a30ec7d94c3a | 20 | PwmOut eye_L(PB_1); |
abanum | 0:a30ec7d94c3a | 21 | WT20003M03 myaudio(PC_10,PC_11); |
abanum | 0:a30ec7d94c3a | 22 | Motorfader myfader(PC_0,A0,A1); |
abanum | 0:a30ec7d94c3a | 23 | Ticker _flipper; |
abanum | 0:a30ec7d94c3a | 24 | // LED |
abanum | 0:a30ec7d94c3a | 25 | //DigitalOut red(PB_5); |
abanum | 0:a30ec7d94c3a | 26 | //DigitalOut yellow(PA_10); |
abanum | 0:a30ec7d94c3a | 27 | |
abanum | 0:a30ec7d94c3a | 28 | void int_frame() { |
abanum | 0:a30ec7d94c3a | 29 | myfader.update(); |
abanum | 0:a30ec7d94c3a | 30 | } |
abanum | 0:a30ec7d94c3a | 31 | |
abanum | 0:a30ec7d94c3a | 32 | int main() |
abanum | 0:a30ec7d94c3a | 33 | { |
abanum | 0:a30ec7d94c3a | 34 | float panchPos,tempR,tempL; |
abanum | 0:a30ec7d94c3a | 35 | |
abanum | 0:a30ec7d94c3a | 36 | _flipper.attach(&int_frame, 0.01f); |
abanum | 0:a30ec7d94c3a | 37 | myaudio.Play(0x0001); |
abanum | 0:a30ec7d94c3a | 38 | // myaudio.Play(0xfff0); |
abanum | 0:a30ec7d94c3a | 39 | /* |
abanum | 0:a30ec7d94c3a | 40 | myaudio.volume(1); |
abanum | 0:a30ec7d94c3a | 41 | myaudio.Play(0x0001); |
abanum | 0:a30ec7d94c3a | 42 | wait(3.0); // 1 second |
abanum | 0:a30ec7d94c3a | 43 | myaudio.volume(16); |
abanum | 0:a30ec7d94c3a | 44 | myaudio.Play(); |
abanum | 0:a30ec7d94c3a | 45 | wait(3.0); // 1 second |
abanum | 0:a30ec7d94c3a | 46 | myaudio.volume(31); |
abanum | 0:a30ec7d94c3a | 47 | myaudio.Play(); |
abanum | 0:a30ec7d94c3a | 48 | printf("s=%d",myaudio.ReadState()); |
abanum | 0:a30ec7d94c3a | 49 | wait(3.0); // 1 second |
abanum | 0:a30ec7d94c3a | 50 | |
abanum | 0:a30ec7d94c3a | 51 | |
abanum | 0:a30ec7d94c3a | 52 | myfader.set(0.0,1.0); |
abanum | 0:a30ec7d94c3a | 53 | wait(3.0); // 1 second |
abanum | 0:a30ec7d94c3a | 54 | myfader.set(0.5,1.0); |
abanum | 0:a30ec7d94c3a | 55 | wait(3.0); // 1 second |
abanum | 0:a30ec7d94c3a | 56 | myfader.set(1.0,1.0); |
abanum | 0:a30ec7d94c3a | 57 | wait(3.0); // 1 second |
abanum | 0:a30ec7d94c3a | 58 | myfader.set(0.5,1.0); |
abanum | 0:a30ec7d94c3a | 59 | wait(3.0); // 1 second |
abanum | 0:a30ec7d94c3a | 60 | */ |
abanum | 0:a30ec7d94c3a | 61 | |
abanum | 0:a30ec7d94c3a | 62 | // USB Gmaepad Initialize |
abanum | 0:a30ec7d94c3a | 63 | pad = new USBHostGamepad(); |
abanum | 0:a30ec7d94c3a | 64 | if (!pad->connect()) { |
abanum | 0:a30ec7d94c3a | 65 | printf("USB Gamepad not found.\r\n"); |
abanum | 0:a30ec7d94c3a | 66 | while(1); |
abanum | 0:a30ec7d94c3a | 67 | } |
abanum | 0:a30ec7d94c3a | 68 | |
abanum | 0:a30ec7d94c3a | 69 | while(((pad->report[6] != 0xf7) && (pad->report[7] != 0xb9))) |
abanum | 0:a30ec7d94c3a | 70 | { |
abanum | 0:a30ec7d94c3a | 71 | USBHost::poll(); |
abanum | 0:a30ec7d94c3a | 72 | wait_ms(16); |
abanum | 0:a30ec7d94c3a | 73 | } |
abanum | 0:a30ec7d94c3a | 74 | while(1) |
abanum | 0:a30ec7d94c3a | 75 | { |
abanum | 0:a30ec7d94c3a | 76 | USBHost::poll(); |
abanum | 0:a30ec7d94c3a | 77 | |
abanum | 0:a30ec7d94c3a | 78 | // red = pad->report[4] & 0x20; |
abanum | 0:a30ec7d94c3a | 79 | // yellow = pad->report[4] & 0x40; |
abanum | 0:a30ec7d94c3a | 80 | |
abanum | 0:a30ec7d94c3a | 81 | // printf("%02x %02x %02x %02x %02x %02x %02x %02x\r\n", pad->report[0],pad->report[1],pad->report[2],pad->report[3],pad->report[4],pad->report[5],pad->report[6],pad->report[7]); |
abanum | 0:a30ec7d94c3a | 82 | wait_ms(16); |
abanum | 0:a30ec7d94c3a | 83 | //zengo |
abanum | 0:a30ec7d94c3a | 84 | tempR = ((pad->report[3]))/255.0f; //sayuu |
abanum | 0:a30ec7d94c3a | 85 | tempL = (255.0f-(pad->report[3]))/255.0f; //sayuu |
abanum | 0:a30ec7d94c3a | 86 | //printf("0R=%1.2f L=%1.2f ",tempR,tempL); |
abanum | 0:a30ec7d94c3a | 87 | //kaiten |
abanum | 0:a30ec7d94c3a | 88 | tempR -= (((pad->report[2]))/255.0f)-0.5f; //sayuu |
abanum | 0:a30ec7d94c3a | 89 | tempL += ((255.0f-(pad->report[2]))/255.0f)-0.5f; //sayuu |
abanum | 0:a30ec7d94c3a | 90 | //printf("1R=%1.2f L=%1.2f ",tempR,tempL); |
abanum | 0:a30ec7d94c3a | 91 | if(tempR >1.0f)tempR = 1.0f; |
abanum | 0:a30ec7d94c3a | 92 | if(tempR <0.0f)tempR = 0.0f; |
abanum | 0:a30ec7d94c3a | 93 | if(tempL >1.0f)tempL = 1.0f; |
abanum | 0:a30ec7d94c3a | 94 | if(tempL <0.0f)tempL = 0.0f; |
abanum | 0:a30ec7d94c3a | 95 | //printf("2R=%1.2f L=%1.2f\r\n",tempR,tempL); |
abanum | 0:a30ec7d94c3a | 96 | |
abanum | 0:a30ec7d94c3a | 97 | tyre_R = tempR; |
abanum | 0:a30ec7d94c3a | 98 | tyre_L = tempL; |
abanum | 0:a30ec7d94c3a | 99 | // pad->report[3] //zengo |
abanum | 0:a30ec7d94c3a | 100 | panchPos = (128-(pad->report[4]))/128.0f; |
abanum | 0:a30ec7d94c3a | 101 | if(panchPos < 0.0f) panchPos = 0.0f; |
abanum | 0:a30ec7d94c3a | 102 | myfader.set(panchPos,1.0); |
abanum | 0:a30ec7d94c3a | 103 | |
abanum | 0:a30ec7d94c3a | 104 | if(pad->report[0] & 0x10) |
abanum | 0:a30ec7d94c3a | 105 | { |
abanum | 0:a30ec7d94c3a | 106 | eye_R = 1.0f; |
abanum | 0:a30ec7d94c3a | 107 | eye_L = 1.0f; |
abanum | 0:a30ec7d94c3a | 108 | } |
abanum | 0:a30ec7d94c3a | 109 | if(pad->report[0] & 0x20) |
abanum | 0:a30ec7d94c3a | 110 | { |
abanum | 0:a30ec7d94c3a | 111 | eye_R = 0.0f; |
abanum | 0:a30ec7d94c3a | 112 | eye_L = 0.0f; |
abanum | 0:a30ec7d94c3a | 113 | } |
abanum | 0:a30ec7d94c3a | 114 | if(pad->report[0] & 0x01) |
abanum | 0:a30ec7d94c3a | 115 | { |
abanum | 0:a30ec7d94c3a | 116 | myaudio.Play(0x0001); |
abanum | 0:a30ec7d94c3a | 117 | wait_ms(10); |
abanum | 0:a30ec7d94c3a | 118 | } |
abanum | 0:a30ec7d94c3a | 119 | if(pad->report[0] & 0x02) |
abanum | 0:a30ec7d94c3a | 120 | { |
abanum | 0:a30ec7d94c3a | 121 | myaudio.Play(0x0002); |
abanum | 0:a30ec7d94c3a | 122 | wait_ms(10); |
abanum | 0:a30ec7d94c3a | 123 | } |
abanum | 0:a30ec7d94c3a | 124 | if(pad->report[0] & 0x08) |
abanum | 0:a30ec7d94c3a | 125 | { |
abanum | 0:a30ec7d94c3a | 126 | myaudio.Play(0x0003); |
abanum | 0:a30ec7d94c3a | 127 | wait_ms(10); |
abanum | 0:a30ec7d94c3a | 128 | } |
abanum | 0:a30ec7d94c3a | 129 | printf("s=%d \r\n",myaudio.ReadState()); |
abanum | 0:a30ec7d94c3a | 130 | |
abanum | 0:a30ec7d94c3a | 131 | } |
abanum | 0:a30ec7d94c3a | 132 | } |