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
- Committer:
- mfillinois
- Date:
- 2014-10-08
- Revision:
- 3:b3ec75e9163f
- Parent:
- 2:e9042e88abf1
- Child:
- 5:dda15798ba1f
File content as of revision 3:b3ec75e9163f:
#include "WirelessMousr.h" #define INSTRUCTION 0 #define VELOCITY 1 WirelessMousr::WirelessMousr() : Mousr(), pc(p28, p27) {} //WirelessMousr::WirelessMousr() : Mousr(), pc(USBTX, USBRX) {} int WirelessMousr::init() { pc.attach(this,&WirelessMousr::rxCallback); wait(0.1); return 0; } void WirelessMousr::rxCallback() { char message = this->pc.getc(); // read RX character, clearing interrupt static char oldstate; char newstate; float pwmval; int numerator; float denominator; this->pc.putc(message); this->pc.putc('\n'); newstate = message; if ((oldstate == 'l') || (oldstate == 'r')) { this->pc.putc('V'); numerator = ((int)message - 128); denominator = (float) 128; pwmval = ((float) numerator) / denominator; if (oldstate == 'l') { this->lefttire(pwmval); this->pc.putc('L'); this->pc.putc('L'); } else if (oldstate == 'r') { this->righttire(pwmval); this->pc.putc('R'); this->pc.putc('R'); } } else { switch(message) { case 'q': //STOP this->left90(); this->pc.putc('L'); this->pc.putc('9'); this->pc.putc('0'); this->pc.putc('\n'); break; case 'a': //STRAIGHT this->left180(); this->pc.putc('L'); this->pc.putc('8'); this->pc.putc('0'); this->pc.putc('\n'); break; case 'e': //STRAIGHT SLOW this->right90(); this->pc.putc('R'); this->pc.putc('9'); this->pc.putc('0'); this->pc.putc('\n'); break; case 'd': //ROTATE LEFT MEDIUM this->right180(); this->pc.putc('R'); this->pc.putc('8'); this->pc.putc('0'); this->pc.putc('\n'); break; case 's': //ROTATE RIGHT MEDIUM this->stop(); this->pc.putc('S'); this->pc.putc('T'); this->pc.putc('P'); this->pc.putc('\n'); break; } } // } oldstate = newstate; }