- This code combines steering and driving in one ticker - Fault check is in a ticker instead of while loop

Dependencies:   mbed MMA8451Q

Committer:
aalawfi
Date:
Mon Oct 25 17:39:23 2021 +0000
Revision:
9:5f032ca6c9b5
Parent:
3:25c6bf0abc00
- fixed some bugs

Who changed what in which revision?

UserRevisionLine numberNew contents of line
aalawfi 3:25c6bf0abc00 1 #define BLUETOOTHBAUDRATE 115200 //Communication rate of the micro-controller
aalawfi 3:25c6bf0abc00 2 //to the Bluetooth module
aalawfi 3:25c6bf0abc00 3 #define SERIALTXPORT PTE0 //Tx Pin (Sends information to serial device)
aalawfi 3:25c6bf0abc00 4 #define SERIALRXPORT PTE1 //Rx Pin (Receives information from serial
aalawfi 3:25c6bf0abc00 5 Serial bt(SERIALTXPORT, SERIALRXPORT); //(TX, RX) Serial declaration for new serial
aalawfi 3:25c6bf0abc00 6
aalawfi 3:25c6bf0abc00 7 char newInputChar;
aalawfi 3:25c6bf0abc00 8 int newInputInt;
aalawfi 3:25c6bf0abc00 9 volatile bool newData = false;
aalawfi 3:25c6bf0abc00 10
aalawfi 3:25c6bf0abc00 11 void btReceive() { //comment this out if it's fucked
aalawfi 3:25c6bf0abc00 12
aalawfi 3:25c6bf0abc00 13 static char buffer[6];
aalawfi 3:25c6bf0abc00 14 static int serialCount = 0;
aalawfi 3:25c6bf0abc00 15
aalawfi 3:25c6bf0abc00 16 {
aalawfi 3:25c6bf0abc00 17 char byteIn = bt.getc();
aalawfi 3:25c6bf0abc00 18 // bt.printf("Got %c",byteIn);
aalawfi 3:25c6bf0abc00 19 if (byteIn == 'n') {
aalawfi 3:25c6bf0abc00 20 buffer[serialCount] = 0;
aalawfi 3:25c6bf0abc00 21 //bt.printf("Got endl %c",byteIn);
aalawfi 3:25c6bf0abc00 22 int speed;
aalawfi 3:25c6bf0abc00 23 char type;
aalawfi 3:25c6bf0abc00 24 if (sscanf(buffer,"%c%i",&type,&speed) == 2) {
aalawfi 3:25c6bf0abc00 25 newInputChar = type;
aalawfi 3:25c6bf0abc00 26 // bt.printf("char: %c", type);
aalawfi 3:25c6bf0abc00 27 newInputInt = speed;
aalawfi 3:25c6bf0abc00 28 // bt.printf("speed: %i", speed);
aalawfi 3:25c6bf0abc00 29 newData = true;
aalawfi 3:25c6bf0abc00 30 }
aalawfi 3:25c6bf0abc00 31 serialCount = 0;
aalawfi 3:25c6bf0abc00 32 } else {
aalawfi 3:25c6bf0abc00 33 buffer[serialCount] = byteIn;
aalawfi 3:25c6bf0abc00 34 if (serialCount < 6)
aalawfi 3:25c6bf0abc00 35 serialCount++;
aalawfi 3:25c6bf0abc00 36 }
aalawfi 3:25c6bf0abc00 37 }
aalawfi 3:25c6bf0abc00 38 }