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 mbed-rtos Motor PowerControl
main.cpp
00001 #include "mbed.h" 00002 #include "Motor.h" 00003 #include "rtos.h" 00004 00005 #include "PowerControl/PowerControl.h" 00006 #include "PowerControl/EthernetPowerControl.h" 00007 00008 Serial blue(p13,p14); 00009 Motor m1(p25, p26, p27); // pwm, fwd, rev 00010 Motor m2(p24, p30, p29); // pwm, fwd, rev 00011 DigitalOut myled1(LED1); 00012 DigitalOut myled2(LED2); 00013 DigitalOut myled3(LED3); 00014 DigitalOut myled4(LED4); 00015 00016 00017 float past_values[3]; 00018 int past_index = 0; 00019 00020 int warningCounter = 0; 00021 int clearCounter = 0; 00022 00023 00024 int main() 00025 { 00026 // you can set the speeds within the case statements or you can write it using functions. 00027 while(1) { 00028 char bnum=0; 00029 char bhit=0; 00030 if (blue.getc()=='!') { 00031 if (blue.getc()=='B') { //button data packet 00032 bnum = blue.getc(); //button number 00033 bhit = blue.getc(); //1=hit, 0=release 00034 if (blue.getc()==char(~('!' + 'B' + bnum + bhit))) { //checksum OK? 00035 switch (bnum) { 00036 case '1': //number button 1 00037 if (bhit=='1') { 00038 //add hit code here 00039 } else { 00040 //add release code here 00041 } 00042 break; 00043 case '2': //number button 2 00044 if (bhit=='1') { 00045 //add hit code here 00046 } else { 00047 //add release code here 00048 } 00049 break; 00050 case '3': //number button 3 00051 if (bhit=='1') { 00052 //add hit code here 00053 } else { 00054 //add release code here 00055 } 00056 break; 00057 case '4': //number button 4 00058 if (bhit=='1') { 00059 //add hit code here 00060 } else { 00061 //add release code here 00062 } 00063 break; 00064 case '5': //button 5 up arrow 00065 if (bhit=='1') { 00066 m1.speed(0.1); 00067 myled1 = 1; 00068 00069 } else { 00070 m1.speed(0.0); 00071 myled1 = 0; 00072 //add release code here 00073 } 00074 break; 00075 case '6': //button 6 down arrow 00076 if (bhit=='1') { 00077 //add hit code here 00078 00079 } else { 00080 00081 //add release code here 00082 } 00083 break; 00084 case '7': //button 7 left arrow 00085 if (bhit=='1') { 00086 00087 //add hit code here 00088 } else { 00089 00090 //add release code here 00091 } 00092 break; 00093 case '8': //button 8 right arrow 00094 if (bhit=='1') { 00095 //add hit code here 00096 00097 } else { 00098 00099 //add release code here 00100 } 00101 break; 00102 default: 00103 break; 00104 } 00105 } 00106 } 00107 } 00108 } 00109 00110 00111 00112 } 00113
Generated on Fri Sep 9 2022 17:08:49 by
1.7.2