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
Diff: effects/HeartBeatEffect.cpp
- Revision:
- 3:edc6e64bfc65
- Parent:
- 2:ed46f45e1d66
- Child:
- 4:a7a26506c62f
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/effects/HeartBeatEffect.cpp Wed Oct 21 17:12:10 2015 +0000
@@ -0,0 +1,36 @@
+
+#include "HeartBeatEffect.h"
+
+HeartBeatEffect::HeartBeatEffect(RGB* led) : Effect(led){
+ updown = true;
+ brightness = 0;
+}
+
+void HeartBeatEffect::run(){
+ if(updown){
+ brightness += 10;
+ } else {
+ brightness -= 20;
+ }
+
+ if(brightness > 255 || brightness < 0) changeDirection();
+ brightness = saturate(brightness);
+
+ setLight(brightness);
+ wait(0.02 * speed);
+}
+
+void HeartBeatEffect::setLight(int value){
+
+ led->setColor( value << 16);
+}
+
+void HeartBeatEffect::changeDirection(){
+ updown = !updown;
+}
+
+int HeartBeatEffect::saturate(int value){
+ if(value > 255) value = 255;
+ if(value < 0) value = 0;
+ return value;
+}