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.
Diff: main.cpp
- Revision:
- 0:cc59ecac5a32
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Wed Dec 19 09:07:41 2018 +0000
@@ -0,0 +1,67 @@
+#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
+ }
+}
\ No newline at end of file