joystick_bjk

Dependencies:   mbed VL53L1X

Committer:
Bhoney
Date:
Tue Aug 27 04:52:07 2019 +0000
Revision:
1:fd1e7e2d0780
Parent:
0:6f0f41537e2f
Child:
2:284491e0f6bf
init

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Bhoney 0:6f0f41537e2f 1 #include "mbed.h"
Bhoney 1:fd1e7e2d0780 2 #include "VL53L1X.h"
Bhoney 1:fd1e7e2d0780 3 #include "CONFIG.h"
Bhoney 1:fd1e7e2d0780 4 #define DEBUG
Bhoney 0:6f0f41537e2f 5
Bhoney 1:fd1e7e2d0780 6 #ifdef DEBUG
Bhoney 1:fd1e7e2d0780 7 DigitalOut led(LED1);
Bhoney 1:fd1e7e2d0780 8 #endif
Bhoney 0:6f0f41537e2f 9
Bhoney 1:fd1e7e2d0780 10 Serial bt(BLUETOOTH_TX, BLUETOOTH_RX);
Bhoney 1:fd1e7e2d0780 11 //Serial pc(USBTX, USBRX);
Bhoney 0:6f0f41537e2f 12
Bhoney 1:fd1e7e2d0780 13 #ifdef ToF
Bhoney 1:fd1e7e2d0780 14 VL53L1X tof(ToF_I2C_SDA, ToF_I2C_SCL); //F303K8(PB_7, PB_6), F072RB(PB_9, PB_8)
Bhoney 0:6f0f41537e2f 15
Bhoney 1:fd1e7e2d0780 16 DigitalOut Xshut1(ToF_XShut_1);
Bhoney 1:fd1e7e2d0780 17 DigitalOut Xshut2(ToF_XShut_2);
Bhoney 1:fd1e7e2d0780 18 DigitalOut Xshut3(ToF_XShut_3);
Bhoney 1:fd1e7e2d0780 19 #endif
Bhoney 0:6f0f41537e2f 20
Bhoney 1:fd1e7e2d0780 21 DigitalOut reverseR(MOTOR_REVERSE_R);
Bhoney 1:fd1e7e2d0780 22 DigitalOut reverseL(MOTOR_REVERSE_L);
Bhoney 0:6f0f41537e2f 23
Bhoney 1:fd1e7e2d0780 24 AnalogOut throttleR(MOTOR_THROTTLE_R);
Bhoney 1:fd1e7e2d0780 25 AnalogOut throttleL(MOTOR_THROTTLE_L);
Bhoney 1:fd1e7e2d0780 26
Bhoney 1:fd1e7e2d0780 27 char rxChar = 0;
Bhoney 1:fd1e7e2d0780 28 bool rxFlag = false;
Bhoney 0:6f0f41537e2f 29
Bhoney 1:fd1e7e2d0780 30 void rxData(){
Bhoney 1:fd1e7e2d0780 31 rxChar = bt.getc();
Bhoney 1:fd1e7e2d0780 32 bt.putc(0);
Bhoney 1:fd1e7e2d0780 33 rxFlag = true;
Bhoney 1:fd1e7e2d0780 34 }
Bhoney 0:6f0f41537e2f 35
Bhoney 0:6f0f41537e2f 36 int main()
Bhoney 0:6f0f41537e2f 37 {
Bhoney 1:fd1e7e2d0780 38 bt.baud(UART_BAUD);
Bhoney 1:fd1e7e2d0780 39 bt.attach(&rxData, Serial::RxIrq);
Bhoney 0:6f0f41537e2f 40 int i = 1;
Bhoney 1:fd1e7e2d0780 41 // Xshut1 = 1;
Bhoney 0:6f0f41537e2f 42
Bhoney 1:fd1e7e2d0780 43 // bt.printf("Hello World !\n");
Bhoney 0:6f0f41537e2f 44
Bhoney 1:fd1e7e2d0780 45 // tof.begin();
Bhoney 1:fd1e7e2d0780 46 // tof.setDistanceMode();
Bhoney 1:fd1e7e2d0780 47
Bhoney 0:6f0f41537e2f 48 while(1) {
Bhoney 1:fd1e7e2d0780 49
Bhoney 1:fd1e7e2d0780 50 if(rxFlag)
Bhoney 1:fd1e7e2d0780 51 {
Bhoney 1:fd1e7e2d0780 52 #ifdef DEBUG
Bhoney 1:fd1e7e2d0780 53 bt.puts("get\r\n");
Bhoney 1:fd1e7e2d0780 54 #endif
Bhoney 1:fd1e7e2d0780 55
Bhoney 1:fd1e7e2d0780 56 switch(rxChar){
Bhoney 1:fd1e7e2d0780 57 case '1':
Bhoney 1:fd1e7e2d0780 58 throttleR = throttleR + DAC_ONE_STEP;
Bhoney 1:fd1e7e2d0780 59 break;
Bhoney 1:fd1e7e2d0780 60
Bhoney 1:fd1e7e2d0780 61 case '2':
Bhoney 1:fd1e7e2d0780 62 throttleR = throttleR - DAC_ONE_STEP;
Bhoney 1:fd1e7e2d0780 63 break;
Bhoney 1:fd1e7e2d0780 64
Bhoney 1:fd1e7e2d0780 65 case '3':
Bhoney 1:fd1e7e2d0780 66 throttleL = throttleL + DAC_ONE_STEP;
Bhoney 1:fd1e7e2d0780 67 break;
Bhoney 1:fd1e7e2d0780 68
Bhoney 1:fd1e7e2d0780 69 case '4':
Bhoney 1:fd1e7e2d0780 70 throttleL = throttleL - DAC_ONE_STEP;
Bhoney 1:fd1e7e2d0780 71 break;
Bhoney 1:fd1e7e2d0780 72
Bhoney 1:fd1e7e2d0780 73 case '5':
Bhoney 1:fd1e7e2d0780 74 reverseR = !reverseR;
Bhoney 1:fd1e7e2d0780 75 break;
Bhoney 1:fd1e7e2d0780 76
Bhoney 1:fd1e7e2d0780 77 case '6':
Bhoney 1:fd1e7e2d0780 78 reverseL = !reverseL;
Bhoney 1:fd1e7e2d0780 79 break;
Bhoney 1:fd1e7e2d0780 80
Bhoney 1:fd1e7e2d0780 81 default:
Bhoney 1:fd1e7e2d0780 82 reverseR = 0;
Bhoney 1:fd1e7e2d0780 83 reverseL = 0;
Bhoney 1:fd1e7e2d0780 84 throttleL = 0;
Bhoney 1:fd1e7e2d0780 85 throttleR
Bhoney 1:fd1e7e2d0780 86
Bhoney 1:fd1e7e2d0780 87
Bhoney 1:fd1e7e2d0780 88
Bhoney 1:fd1e7e2d0780 89 = 0;
Bhoney 1:fd1e7e2d0780 90
Bhoney 1:fd1e7e2d0780 91
Bhoney 1:fd1e7e2d0780 92 }
Bhoney 1:fd1e7e2d0780 93 rxFlag = false;
Bhoney 1:fd1e7e2d0780 94 }
Bhoney 1:fd1e7e2d0780 95
Bhoney 0:6f0f41537e2f 96 }
Bhoney 0:6f0f41537e2f 97 }