segway_self balancing robot 4180 project
Dependencies: mbed mbed-rtos LSM9DS1_Library
Revision 12:980c06d63425, committed 2020-04-18
- Comitter:
- pandirimukund
- Date:
- Sat Apr 18 20:45:02 2020 +0000
- Parent:
- 11:c669b4dc1f9f
- Child:
- 13:c00ddcfea79f
- Commit message:
- prettify code;
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sat Apr 18 20:35:58 2020 +0000
+++ b/main.cpp Sat Apr 18 20:45:02 2020 +0000
@@ -13,72 +13,72 @@
float rd = 51;
float ri = 50;
float desired_angle = 0;
-Serial blue(p28,p27);
+Serial blue(p28, p27);
void bluetooth_update() {
- char bnum=0;
- char bhit=0;
- while(1){
- if (blue.getc()=='!') {
- if (blue.getc()=='B') { //button data packet
- bnum = blue.getc(); //button number
- //pc.printf("%d",bnum);
- bhit = blue.getc(); //1=hit, 0=release
- parametersmutex.lock();
- if (blue.getc()==char(~('!' + 'B' + bnum + bhit))) { //checksum OK?
- myled = bnum - '0'; //current button number will appear on LEDs
- switch (bnum) {
+ char bnum = 0;
+ char bhit = 0;
+ while (1) {
+ if (blue.getc() == '!') {
+ if (blue.getc() == 'B') { //button data packet
+ bnum = blue.getc(); //button number
+ //pc.printf("%d",bnum);
+ bhit = blue.getc(); //1=hit, 0=release
+ parametersmutex.lock();
+ if (blue.getc() == char(~('!' + 'B' + bnum + bhit))) { //checksum OK?
+ myled = bnum - '0'; //current button number will appear on LEDs
+ switch (bnum) {
case '1': //number button 1
- if (bhit=='1') {
+ if (bhit == '1') {
rd += 1;
} else {
//add release code here
}
break;
case '2': //number button 2
- if (bhit=='1') {
+ if (bhit == '1') {
ri += 1;
} else {
//add release code here
}
break;
case '3': //number button 3
- if (bhit=='1') {
+ if (bhit == '1') {
rd -= 1;
} else {
//add release code here
}
break;
case '4': //number button 4
- if (bhit=='1') {
+ if (bhit == '1') {
ri -= 1;
} else {
//add release code here
}
break;
case '5': //button 5 up arrow
- if (bhit=='1') {
+ if (bhit == '1') {
rp += 1;
} else {
//add release code here
}
break;
case '6': //button 6 down arrow
- if (bhit=='1') {
+ if (bhit == '1') {
rp -= 1;
} else {
//add release code here
}
break;
case '7': //button 7 left arrow
- if (bhit=='1') {
+ if (bhit == '1') {
desired_angle -= 1;
} else {
//add release code here
}
break;
case '8': //button 8 right arrow
- if (bhit=='1') {
+ if (bhit == '1') {
desired_angle += 1;
} else {
//add release code here
@@ -86,12 +86,12 @@
break;
default:
break;
+ }
}
+ parametersmutex.unlock();
}
- parametersmutex.unlock();
}
- }
- Thread::wait(100);
+ Thread::wait(100);
}
}
@@ -100,7 +100,7 @@
Thread bluetooth;
bluetooth.start(bluetooth_update);
//bluetooth.attach(&bluetooth_update, 0.1);
- while(1) {
+ while (1) {
//bluetooth_update();
parametersmutex.lock();
pc.printf("rp: %f, rd: %f, ri: %f, desired_angle: %f\n", rp, rd, ri, desired_angle);
