Added a basic pulse to the light

This commit is contained in:
mrcory
2019-05-24 12:23:39 -04:00
parent eca735a637
commit 0c87a1a4b0
4 changed files with 40 additions and 0 deletions
+2
View File
@@ -76,6 +76,8 @@ const int stepPerRev = 4096; //Steps needed to make 1 revolution
*/
int ledBrightness = 2; //Starting brightness
int ledButtonBrightness = 50; //Brightness to use when using rst button to turn on light.
int pulseMax = 250; //Max brightness for pulse mode. Max 250 or it will loop to near 0
//Can be set in Blynk
//FastLED Settings
#define NUM_LEDS 9 //Number of attached LEDs
+10
View File
@@ -158,4 +158,14 @@ void moveNow() {
}
#endif
unsigned long timer = millis();
bool timerFunc(int _comp) {
if (millis() - timer >= _comp) {
return true;
timer = millis();
} else {
return false;
}
}
+16
View File
@@ -57,11 +57,13 @@ int motorPos = 0;
unsigned long ledTimer;
bool ledFeedback = false;
byte ledMode = 0;
bool pulse = false; //Basic effect
bool lightOn = false;
bool lightOld = true;
int oldBrightness = ledBrightness;
int currentColor[3] = {255,255,255};
int pulseSpeed = 2;
#include "wifi.h"
@@ -251,6 +253,20 @@ void lightControl() {
fill_solid(leds,NUM_LEDS,CRGB(0,0,0));
}
lightOld = lightOn;
static bool _direction = false; //Flag for fade direction
if (pulse == true) {
if (timerFunc(pulseSpeed)) {
if (_direction == true) {
if (ledBrightness < pulseMax) { ledBrightness+=2; } else {_direction = false;}
}
if (_direction == false) {
if (ledBrightness > 5) { ledBrightness-=2; } else {_direction = true;}
}
}
}
}
+12
View File
@@ -36,3 +36,15 @@ BLYNK_WRITE(V23) {
currentColor[2] = param[2].asInt();
}
BLYNK_WRITE(V24) {
pulse = param.asInt();
}
BLYNK_WRITE(V25) {
pulseSpeed = param.asInt();
}
BLYNK_WRITE(V26) {
pulseMax = param.asInt();
}