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
Fork of RCControlOOP by
WirelessMousr.cpp
00001 #include "WirelessMousr.h" 00002 00003 WirelessMousr::WirelessMousr() : Mousr(), pc(p28, p27) {} //USE FOR BT 00004 //WirelessMousr::WirelessMousr() : Mousr(), pc(USBTX, USBRX) {} //USE FOR USB 00005 00006 int WirelessMousr::init() 00007 { 00008 pc.attach(this,&WirelessMousr::rxCallback); 00009 wait(0.1); 00010 return 0; 00011 } 00012 00013 void WirelessMousr::rxCallback() 00014 { 00015 char message = this->pc.getc(); // read RX character, clearing interrupt 00016 static char oldstate; 00017 char newstate; 00018 float pwmval; 00019 int numerator; 00020 float denominator; 00021 this->pc.putc(message); 00022 //this->pc.putc('\n'); 00023 //this->pc.putc('\r'); 00024 newstate = message; 00025 00026 00027 if ((oldstate == 'L') || (oldstate == 'R')) 00028 { 00029 //this->pc.putc('V'); 00030 00031 numerator = ((int)message - 50); 00032 denominator = (float) 50; 00033 pwmval = ((float) numerator) / denominator; 00034 //pc.printf("%f \n \r",pwmval); 00035 //pc.printf("%d",message); 00036 00037 if (oldstate == 'L') 00038 { 00039 this->lefttire(pwmval); 00040 //this->pc.putc('L'); 00041 //this->pc.putc('L'); 00042 } 00043 else if (oldstate == 'R') 00044 { 00045 this->righttire(pwmval); 00046 //this->pc.putc('R'); 00047 //this->pc.putc('R'); 00048 } 00049 } 00050 else 00051 { 00052 switch(message) 00053 { 00054 case 'q': //STOP 00055 this->left90(); 00056 /*this->pc.putc('L'); 00057 this->pc.putc('9'); 00058 this->pc.putc('0'); 00059 this->pc.putc('\n');*/ 00060 break; 00061 case 'a': //STRAIGHT 00062 this->left180(); 00063 /* this->pc.putc('L'); 00064 this->pc.putc('8'); 00065 this->pc.putc('0'); 00066 this->pc.putc('\n');*/ 00067 break; 00068 case 'e': //STRAIGHT SLOW 00069 this->right90(); 00070 /* this->pc.putc('R'); 00071 this->pc.putc('9'); 00072 this->pc.putc('0'); 00073 this->pc.putc('\n');*/ 00074 break; 00075 case 'd': //ROTATE LEFT MEDIUM 00076 this->right180(); 00077 /* this->pc.putc('R'); 00078 this->pc.putc('8'); 00079 this->pc.putc('0'); 00080 this->pc.putc('\n');*/ 00081 break; 00082 case 's': //ROTATE RIGHT MEDIUM 00083 this->stop(); 00084 /* this->pc.putc('S'); 00085 this->pc.putc('T'); 00086 this->pc.putc('P'); 00087 this->pc.putc('\n'); break;*/ 00088 } 00089 } 00090 oldstate = newstate; 00091 }
Generated on Wed Jul 20 2022 17:06:22 by
