joystick_bjk

Dependencies:   mbed VL53L1X

main.cpp

Committer:
Bhoney
Date:
14 months ago
Revision:
1:fd1e7e2d0780
Parent:
0:6f0f41537e2f
Child:
2:284491e0f6bf

File content as of revision 1:fd1e7e2d0780:

#include "mbed.h"
#include "VL53L1X.h"
#include "CONFIG.h"
#define DEBUG

#ifdef DEBUG
DigitalOut led(LED1);
#endif

Serial bt(BLUETOOTH_TX, BLUETOOTH_RX);
//Serial pc(USBTX, USBRX);

#ifdef ToF
VL53L1X tof(ToF_I2C_SDA, ToF_I2C_SCL);    //F303K8(PB_7, PB_6), F072RB(PB_9, PB_8)

DigitalOut Xshut1(ToF_XShut_1);
DigitalOut Xshut2(ToF_XShut_2);
DigitalOut Xshut3(ToF_XShut_3);
#endif

DigitalOut reverseR(MOTOR_REVERSE_R);
DigitalOut reverseL(MOTOR_REVERSE_L);

AnalogOut throttleR(MOTOR_THROTTLE_R);
AnalogOut throttleL(MOTOR_THROTTLE_L);

char rxChar = 0;
bool rxFlag = false;

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;

//    bt.printf("Hello World !\n");

//    tof.begin();
//    tof.setDistanceMode();
    
    while(1) {
        
        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;
        }

    }
}