Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed Servo mbed-rtos X_NUCLEO_53L0A1
Diff: main.cpp
- Revision:
- 13:74d440e3000b
- Parent:
- 12:dd53c18e9cf2
- Child:
- 14:63c2b3d14d06
--- a/main.cpp Thu Apr 23 23:53:58 2020 +0000
+++ b/main.cpp Fri Apr 24 17:12:31 2020 +0000
@@ -4,6 +4,9 @@
#include "Servo.h"
#include <stdio.h>
+//BusOut myleds(LED4,LED3,LED2,LED1); //LEDS for debugging
+
+Serial blue(p13,p14);
Serial pc(USBTX,USBRX);
Servo myservo(p21);
DigitalOut shdn(p26);
@@ -18,6 +21,7 @@
Thread lidar_thread;
Thread motor_thread;
+Thread bluetooth_thread;
uint32_t volatile distance_copy;
int volatile status;
@@ -77,6 +81,60 @@
}
}
+void speed_control()
+{
+ char bnum=0;
+ char bhit=0;
+ //myleds = 0;
+ while(1) {
+ if (blue.getc()=='!') {
+ if (blue.getc()=='B') { //button data packet
+ bnum = blue.getc(); //button number
+ bhit = blue.getc(); //1=hit, 0=release
+ if (blue.getc()==char(~('!' + 'B' + bnum + bhit))) { //checksum OK?
+ switch (bnum) {
+
+ case '5': //button 5 up arrow - Increase fan speed.
+ if (bhit=='1')
+ {
+ if( on_speed < 0.95 )
+ {
+ speed_lock.lock();
+ on_speed = on_speed + .1;
+ speed_lock.unlock();
+ //myleds = myleds + 1;
+ }
+ }
+ break;
+
+ case '6': //button 6 down arrow - Decrease fan speed.
+ if (bhit=='1') {
+ if( on_speed > 0.05 )
+ {
+ speed_lock.lock();
+ on_speed = on_speed - 0.1;
+ speed_lock.unlock();
+ //myleds = myleds - 1;
+ }
+ }
+ break;
+
+ case '7': //button 7 left arrow - Turn fan off.
+ if (bhit=='1') {
+ speed_lock.lock();
+ on_speed = 0;
+ speed_lock.unlock();
+ //myleds = 0;
+ }
+ break;
+ }
+ }
+ }
+ }
+ }
+}
+
+
int main()
{
DevI2C *device_i2c = new DevI2C(VL53L0_I2C_SDA, VL53L0_I2C_SCL);
@@ -104,4 +162,5 @@
lidar_thread.start(check_distance);
motor_thread.start(fan_control);
+ bluetooth_thread.start(speed_control);
}