Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed Motorfader Servo WT2003M03
main.cpp
00001 #include "mbed.h" 00002 #include "USBHostGamepad.h" 00003 #include "Servo.h" 00004 #include "WT2003M03.h" 00005 #include "Motorfader.h" 00006 #include "stdio.h" 00007 #include "stdlib.h" 00008 #include "math.h" 00009 #include "string" 00010 00011 #define SCREEN_WIDTH 128 00012 #define SCREEN_HEIGHT 160 00013 00014 USBHostGamepad *pad; 00015 //Servo myservo1(D3); 00016 Servo tyre_R(D5); //TYRE RIGHT 00017 Servo tyre_L(D6); //TYRE LEFT 00018 //Servo myservo4(D4); 00019 PwmOut eye_R(PB_2); 00020 PwmOut eye_L(PB_1); 00021 WT20003M03 myaudio(PC_10,PC_11); 00022 Motorfader myfader(PC_0,A0,A1); 00023 Ticker _flipper; 00024 // LED 00025 //DigitalOut red(PB_5); 00026 //DigitalOut yellow(PA_10); 00027 00028 void int_frame() { 00029 myfader.update(); 00030 } 00031 00032 int main() 00033 { 00034 float panchPos,tempR,tempL; 00035 00036 _flipper.attach(&int_frame, 0.01f); 00037 myaudio.Play(0x0001); 00038 // myaudio.Play(0xfff0); 00039 /* 00040 myaudio.volume(1); 00041 myaudio.Play(0x0001); 00042 wait(3.0); // 1 second 00043 myaudio.volume(16); 00044 myaudio.Play(); 00045 wait(3.0); // 1 second 00046 myaudio.volume(31); 00047 myaudio.Play(); 00048 printf("s=%d",myaudio.ReadState()); 00049 wait(3.0); // 1 second 00050 00051 00052 myfader.set(0.0,1.0); 00053 wait(3.0); // 1 second 00054 myfader.set(0.5,1.0); 00055 wait(3.0); // 1 second 00056 myfader.set(1.0,1.0); 00057 wait(3.0); // 1 second 00058 myfader.set(0.5,1.0); 00059 wait(3.0); // 1 second 00060 */ 00061 00062 // USB Gmaepad Initialize 00063 pad = new USBHostGamepad(); 00064 if (!pad->connect()) { 00065 printf("USB Gamepad not found.\r\n"); 00066 while(1); 00067 } 00068 00069 while(((pad->report[6] != 0xf7) && (pad->report[7] != 0xb9))) 00070 { 00071 USBHost::poll(); 00072 wait_ms(16); 00073 } 00074 while(1) 00075 { 00076 USBHost::poll(); 00077 00078 // red = pad->report[4] & 0x20; 00079 // yellow = pad->report[4] & 0x40; 00080 00081 // 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]); 00082 wait_ms(16); 00083 //zengo 00084 tempR = ((pad->report[3]))/255.0f; //sayuu 00085 tempL = (255.0f-(pad->report[3]))/255.0f; //sayuu 00086 //printf("0R=%1.2f L=%1.2f ",tempR,tempL); 00087 //kaiten 00088 tempR -= (((pad->report[2]))/255.0f)-0.5f; //sayuu 00089 tempL += ((255.0f-(pad->report[2]))/255.0f)-0.5f; //sayuu 00090 //printf("1R=%1.2f L=%1.2f ",tempR,tempL); 00091 if(tempR >1.0f)tempR = 1.0f; 00092 if(tempR <0.0f)tempR = 0.0f; 00093 if(tempL >1.0f)tempL = 1.0f; 00094 if(tempL <0.0f)tempL = 0.0f; 00095 //printf("2R=%1.2f L=%1.2f\r\n",tempR,tempL); 00096 00097 tyre_R = tempR; 00098 tyre_L = tempL; 00099 // pad->report[3] //zengo 00100 panchPos = (128-(pad->report[4]))/128.0f; 00101 if(panchPos < 0.0f) panchPos = 0.0f; 00102 myfader.set(panchPos,1.0); 00103 00104 if(pad->report[0] & 0x10) 00105 { 00106 eye_R = 1.0f; 00107 eye_L = 1.0f; 00108 } 00109 if(pad->report[0] & 0x20) 00110 { 00111 eye_R = 0.0f; 00112 eye_L = 0.0f; 00113 } 00114 if(pad->report[0] & 0x01) 00115 { 00116 myaudio.Play(0x0001); 00117 wait_ms(10); 00118 } 00119 if(pad->report[0] & 0x02) 00120 { 00121 myaudio.Play(0x0002); 00122 wait_ms(10); 00123 } 00124 if(pad->report[0] & 0x08) 00125 { 00126 myaudio.Play(0x0003); 00127 wait_ms(10); 00128 } 00129 printf("s=%d \r\n",myaudio.ReadState()); 00130 00131 } 00132 }
Generated on Thu Jul 14 2022 06:04:41 by
1.7.2