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
Revision 14:63c2b3d14d06, committed 2020-04-26
- Comitter:
- BubbaLee
- Date:
- Sun Apr 26 20:38:19 2020 +0000
- Parent:
- 13:74d440e3000b
- Commit message:
- Final working code for the Smart Fan
Changed in this revision
--- a/X_NUCLEO_53L0A1.lib Fri Apr 24 17:12:31 2020 +0000 +++ b/X_NUCLEO_53L0A1.lib Sun Apr 26 20:38:19 2020 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/teams/ST/code/X_NUCLEO_53L0A1/#27d3d95c8593 +https://os.mbed.com/users/BubbaLee/code/X_NUCLEO_53L0A1/#e7388f3f9983
--- a/main.cpp Fri Apr 24 17:12:31 2020 +0000
+++ b/main.cpp Sun Apr 26 20:38:19 2020 +0000
@@ -25,7 +25,7 @@
uint32_t volatile distance_copy;
int volatile status;
-double volatile on_speed = .1;
+double volatile on_speed = 0.1;
Mutex distance_lock;
Mutex status_lock;
@@ -47,6 +47,7 @@
if (status == VL53L0X_ERROR_NONE)
{
pc.printf("D=%ld mm\r\n", distance_copy);
+ pc.printf("D=%ld mm\r\n", distance);
}
distance_lock.unlock();
status_lock.unlock();
@@ -58,23 +59,26 @@
{
while (1)
{
- status_lock.lock();
- distance_lock.lock();
+ //status_lock.lock();
+ //distance_lock.lock();
speed_lock.lock();
+ //pc.printf("inside\n");
if (status == VL53L0X_ERROR_NONE)
{
if (distance_copy <= 610) // within 2 feet (distance is in mm)
{
myservo = on_speed;
+ //pc.printf("on\n");
}
else
{
myservo = 0;
+ //pc.printf("off\n");
}
}
- status_lock.unlock();
- distance_lock.unlock();
+ //status_lock.unlock();
+ //distance_lock.unlock();
speed_lock.unlock();
Thread::yield();
@@ -97,10 +101,10 @@
case '5': //button 5 up arrow - Increase fan speed.
if (bhit=='1')
{
- if( on_speed < 0.95 )
+ if( on_speed <= 0.2 )
{
speed_lock.lock();
- on_speed = on_speed + .1;
+ on_speed = on_speed + 0.02;
speed_lock.unlock();
//myleds = myleds + 1;
}
@@ -109,20 +113,29 @@
case '6': //button 6 down arrow - Decrease fan speed.
if (bhit=='1') {
- if( on_speed > 0.05 )
+ if( on_speed >= 0.0 )
{
speed_lock.lock();
- on_speed = on_speed - 0.1;
+ on_speed = on_speed - 0.02;
speed_lock.unlock();
//myleds = myleds - 1;
}
}
break;
- case '7': //button 7 left arrow - Turn fan off.
+ case '1': //button 1 - Turn fan on.
if (bhit=='1') {
speed_lock.lock();
- on_speed = 0;
+ on_speed = 0.1;
+ speed_lock.unlock();
+ //myleds = 0;
+ }
+ break;
+
+ case '2': //button 2 - Turn fan off.
+ if (bhit=='1') {
+ speed_lock.lock();
+ on_speed = 0.0;
speed_lock.unlock();
//myleds = 0;
}
@@ -158,9 +171,12 @@
}
status_lock.unlock();
- myservo = 0;
+ myservo = 0.0;
- lidar_thread.start(check_distance);
- motor_thread.start(fan_control);
- bluetooth_thread.start(speed_control);
+ while(1)
+ {
+ lidar_thread.start(check_distance);
+ motor_thread.start(fan_control);
+ bluetooth_thread.start(speed_control);
+ }
}
--- a/mbed.bld Fri Apr 24 17:12:31 2020 +0000 +++ b/mbed.bld Sun Apr 26 20:38:19 2020 +0000 @@ -1,1 +1,1 @@ -https://mbed.org/users/mbed_official/code/mbed/builds/e2bfab296f20 \ No newline at end of file +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file