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.
Dependents: m3Dpi MQTT-Thermostat-example Final_project_Tran Final_project_Tran ... more
HeartBeatEffect.cpp
00001 00002 #include "HeartBeatEffect.h" 00003 00004 HeartBeatEffect::HeartBeatEffect(RGB* led) : Effect(led) 00005 { 00006 updown = true; 00007 brightness = 0; 00008 } 00009 00010 void HeartBeatEffect::run() 00011 { 00012 if(updown) { 00013 brightness += 10; 00014 } else { 00015 brightness -= 20; 00016 } 00017 00018 if(brightness > 255 || brightness < 0) changeDirection(); 00019 brightness = saturate(brightness); 00020 00021 setLight(brightness); 00022 wait(0.02 * speed); 00023 } 00024 00025 void HeartBeatEffect::setLight(int value) 00026 { 00027 00028 led->setColor( value << 16); 00029 } 00030 00031 void HeartBeatEffect::changeDirection() 00032 { 00033 updown = !updown; 00034 } 00035 00036 int HeartBeatEffect::saturate(int value) 00037 { 00038 if(value > 255) value = 255; 00039 if(value < 0) value = 0; 00040 return value; 00041 }
Generated on Tue Jul 12 2022 13:58:34 by
1.7.2