Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added functionality so that the user led fades over time #51

Merged
merged 1 commit into from
Oct 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions ESP32-SOCKETIO.ino
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,16 @@ using namespace ace_button;
#define FASTLONGFADE 120
unsigned long LONGFADEMINUTESMAX = 360;
#define LONGFADECHECKMILLIS 60000
unsigned long prevLongFadeVal = 0;
unsigned long prevLongFadeVal[NUMPIXELS] = {0,0};
uint8_t hue[NUMPIXELS];
uint8_t saturation[NUMPIXELS];
uint8_t value[NUMPIXELS];
uint8_t prevRemoteSat;
bool ledChanged[NUMPIXELS] = {false, false};
unsigned long prevPixelMillis;
bool isLongFade = false;
bool isLongFade[NUMPIXELS]= {false,false};
unsigned long prevlongPixelMillis;
unsigned long longFadeMinutes;
unsigned long prevLongFadeMillis;
unsigned long longFadeMinutes[NUMPIXELS];
unsigned long prevLongFadeMillis[NUMPIXELS];
bool isRemoteLedFading = false;
CRGB leds[NUMPIXELS];
bool readyToFadeRGB[NUMPIXELS] = {false, false};
Expand Down
44 changes: 24 additions & 20 deletions rgbled.ino
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ void rgbLedHandler() {
if (ledChanged[USERLED]) {
ledChanged[USERLED] = false;
saturation[USERLED] = 255;
value[USERLED] = 255;
leds[USERLED] = CHSV(hue[USERLED], saturation[USERLED], value[USERLED]);
FastLED.show();
}
Expand All @@ -37,7 +36,7 @@ void rgbLedHandler() {
leds[REMOTELED] = CHSV(hue[REMOTELED], saturation[REMOTELED], value[REMOTELED]);
FastLED.show();
}
//long fade on remote led
//long fade
longFadeHandler();
}
//updating every 5 seconds to make sure the leds dont lose their colours
Expand All @@ -50,6 +49,7 @@ void rgbLedHandler() {
}

void cycleHue(int led) {
value[led] = 255;
if (hue[led] < 255) {
hue[led]++;
} else {
Expand Down Expand Up @@ -101,27 +101,31 @@ void fadeRGBHandler() {
}
}

void startLongFade() {
isLongFade = true;
longFadeMinutes = LONGFADEMINUTESMAX;
prevLongFadeVal = 0;
void startLongFade(byte LED) {
isLongFade[LED] = true;
longFadeMinutes[LED] = LONGFADEMINUTESMAX;
prevLongFadeVal[LED] = 0;
}

void longFadeHandler() {
if (isLongFade) {
if (millis() - prevLongFadeMillis > LONGFADECHECKMILLIS) {
prevLongFadeMillis = millis();
longFadeMinutes--;
unsigned long currLongFadeVal = long((float)longFadeMinutes / ((float)LONGFADEMINUTESMAX / (float)RGBLEDPWMSTART));
if (currLongFadeVal != prevLongFadeVal) {
prevLongFadeVal = currLongFadeVal;
currLongFadeVal = currLongFadeVal - 1;
value[REMOTELED] = (byte)fscale(0, RGBLEDPWMSTART, 0, RGBLEDPWMSTART, currLongFadeVal, -3);
ledChanged[REMOTELED] = true;
Serial.println(value[REMOTELED]);
}
if (longFadeMinutes <= 0) {
isLongFade = false;
for (byte i = 0; i < NUMPIXELS; i++) {
if (isLongFade[i]) {
if (millis() - prevLongFadeMillis[i] > LONGFADECHECKMILLIS) {
prevLongFadeMillis[i] = millis();
longFadeMinutes[i]--;
unsigned long currLongFadeVal = long((float)longFadeMinutes[i] / ((float)LONGFADEMINUTESMAX / (float)RGBLEDPWMSTART));
if (currLongFadeVal != prevLongFadeVal[i]) {
prevLongFadeVal[i] = currLongFadeVal;
currLongFadeVal = currLongFadeVal - 1;
value[i] = (byte)fscale(0, RGBLEDPWMSTART, 0, RGBLEDPWMSTART, currLongFadeVal, -3);
ledChanged[i] = true;
Serial.print("LED:");
Serial.println(i);
Serial.println(value[i]);
}
if (longFadeMinutes[i] <= 0) {
isLongFade[i] = false;
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion socketIO.ino
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void socketIO_msg(const char * payload, size_t length) {
//added to enable reset of fading mid fade
isFadingRGB[REMOTELED] = false;
fadeRGB(REMOTELED);
startLongFade();
startLongFade(REMOTELED);
}
else if (String(data_project) == "test") {
blinkDevice();
Expand Down
1 change: 1 addition & 0 deletions utility.ino
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ void handleTouchEvent(AceButton* button, uint8_t eventType, uint8_t buttonState)
} else {
ledChanged[USERLED] = true;
fadeRGB(USERLED);
startLongFade(USERLED);
socketIO_sendColour();
}
isSelectingColour = false;
Expand Down