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.
main.cpp
- Committer:
- pkolar1
- Date:
- 2018-12-19
- Revision:
- 1:a68842ba46f5
- Parent:
- 0:cc59ecac5a32
File content as of revision 1:a68842ba46f5:
#include "mbed.h"
#include "Joystick.h"
Serial pc(USBTX, USBRX);
Joystick joystick(PTB0,PTB1);
Serial serial(PTE0, NC);
DigitalIn master_switch(PTC9);
DigitalOut led_man(LED1);
DigitalOut led_auto(LED2);
void transmit(void);
void conversion(void);
void modeSwitch(void);
bool manual = true;
int direction, aim;
uint8_t tx = 0;
Timeout debounce;
Ticker tick;
void transmit()
{
serial.putc(tx); //tx transmit
return;
}
void conversion()
{
tx = 0;
if(serial.writeable()) {
if(manual == true) {
tx ^= (0x2 << 4); //adding ID key 0x2 (0b0010)
tx = tx + direction; //binding direction and aim
tx = tx + aim;
} else if(manual == false) { //ID key 0x56 (0b01010110)
tx = 0x56;
}
transmit();
}
return;
}
void modeSwitch()
{
if(manual) {
manual = false;
led_auto = 1;
led_man = 0;
} else {
manual = true;
led_man = 1;
led_auto = 0;
}
return;
}
int main()
{
led_man = 1;
led_auto = 0;
tick.attach(&conversion,0.01); //call every 10ms
serial.baud(1200); //frequency
serial.format(8,SerialBase::None,1); //communication(UART)
while(1) {
direction = joystick.DirectionDC(); //call for motors values
aim = joystick.Servo();
if(master_switch == 0) debounce.attach(&modeSwitch,0.2); //autonomous - manual switch
}
}