byeongjin kim
/
Hug2Go_ver_2
joystick_bjk
Diff: main.cpp
- Revision:
- 1:fd1e7e2d0780
- Parent:
- 0:6f0f41537e2f
- Child:
- 2:284491e0f6bf
--- a/main.cpp Sun Aug 25 19:55:53 2019 +0000 +++ b/main.cpp Tue Aug 27 04:52:07 2019 +0000 @@ -1,36 +1,97 @@ #include "mbed.h" +#include "VL53L1X.h" +#include "CONFIG.h" +#define DEBUG -/*------------------------------------------------------------------------------ -Before to use this example, ensure that you an hyperterminal installed on your -computer. More info here: https://developer.mbed.org/handbook/Terminals +#ifdef DEBUG +DigitalOut led(LED1); +#endif -The default serial comm port uses the SERIAL_TX and SERIAL_RX pins (see their -definition in the PinNames.h file). +Serial bt(BLUETOOTH_TX, BLUETOOTH_RX); +//Serial pc(USBTX, USBRX); -The default serial configuration in this case is 9600 bauds, 8-bit data, no parity +#ifdef ToF +VL53L1X tof(ToF_I2C_SDA, ToF_I2C_SCL); //F303K8(PB_7, PB_6), F072RB(PB_9, PB_8) -If you want to change the baudrate for example, you have to redeclare the -serial object in your code: +DigitalOut Xshut1(ToF_XShut_1); +DigitalOut Xshut2(ToF_XShut_2); +DigitalOut Xshut3(ToF_XShut_3); +#endif -Serial pc(SERIAL_TX, SERIAL_RX); +DigitalOut reverseR(MOTOR_REVERSE_R); +DigitalOut reverseL(MOTOR_REVERSE_L); -Then, you can modify the baudrate and print like this: +AnalogOut throttleR(MOTOR_THROTTLE_R); +AnalogOut throttleL(MOTOR_THROTTLE_L); + +char rxChar = 0; +bool rxFlag = false; -pc.baud(115200); -pc.printf("Hello World !\n"); -------------------------------------------------------------------------------*/ - -DigitalOut led(LED1); +void rxData(){ + rxChar = bt.getc(); + bt.putc(0); + rxFlag = true; +} int main() { + bt.baud(UART_BAUD); + bt.attach(&rxData, Serial::RxIrq); int i = 1; +// Xshut1 = 1; - printf("Hello World !\n"); +// bt.printf("Hello World !\n"); +// tof.begin(); +// tof.setDistanceMode(); + while(1) { - wait(1); // 1 second - led = !led; // Toggle LED - printf("This program runs since %d seconds.\n", i++); + + if(rxFlag) + { + #ifdef DEBUG + bt.puts("get\r\n"); + #endif + + switch(rxChar){ + case '1': + throttleR = throttleR + DAC_ONE_STEP; + break; + + case '2': + throttleR = throttleR - DAC_ONE_STEP; + break; + + case '3': + throttleL = throttleL + DAC_ONE_STEP; + break; + + case '4': + throttleL = throttleL - DAC_ONE_STEP; + break; + + case '5': + reverseR = !reverseR; + break; + + case '6': + reverseL = !reverseL; + break; + + default: + reverseR = 0; + reverseL = 0; + throttleL = 0; + throttleR + + + + = 0; + + + } + rxFlag = false; + } + } }