Skip to content

Commit a6eab1b

Browse files
committed
Fixed hasColorChanged mthod.
1 parent cac52de commit a6eab1b

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

examples/CheerLights_Basic/CheerLights_Basic.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ void loop() {
6161
Serial.println(CheerLights.currentColorName());
6262

6363
// Print the current CheerLights color as a hex value
64-
Serial.print("Current CheerLights Color Hex: ");
65-
Serial.println(CheerLights.currentColorHex());
64+
Serial.print("Current CheerLights Color Hex: 0x");
65+
Serial.println(CheerLights.currentColorHex(), HEX);
6666

6767
// Print the current CheerLights color as RGB values
6868
Serial.print("Current CheerLights Color RGB: ");

src/CheerLights.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,18 @@ void CheerLights::_fetchColor() {
5151
lastUpdate = currentTime;
5252

5353
// Check WiFi connection and attempt to reconnect if necessary
54-
if (WiFi.status() != WL_CONNECTED) {
55-
_connectToWiFi();
54+
if (_ssid != nullptr && _password != nullptr) {
5655
if (WiFi.status() != WL_CONNECTED) {
57-
return;
56+
_connectToWiFi();
57+
if (WiFi.status() != WL_CONNECTED) {
58+
return;
59+
}
5860
}
5961
}
6062

6163
const char* host = "api.thingspeak.com";
6264
const int httpPort = 80;
63-
const char* apiPath = "/channels/1417/field/1/last.txt";
65+
const char* apiPath = "/channels/1417/field/1/last.txt?headers=false";
6466

6567
WiFiClient client;
6668
if (!client.connect(host, httpPort)) {
@@ -138,11 +140,13 @@ void CheerLights::_fetchColor() {
138140
_colorHex = 0x000000; // Default to black
139141
for (const auto& color : colorMap) {
140142
if (strcasecmp(_colorName, color.name) == 0) {
141-
_colorHex = color.color;
142-
_previousColorHex = _colorHex;
143+
_colorHex = color.color;
143144
break;
144145
}
145146
}
147+
148+
_colorChanged = _colorHex != _previousColorHex;
149+
_previousColorHex = _colorHex;
146150
}
147151

148152
const char* CheerLights::getCurrentColor() {
@@ -175,5 +179,5 @@ bool CheerLights::isConnected() {
175179
}
176180

177181
bool CheerLights::hasColorChanged() {
178-
return _colorHex != _previousColorHex;
182+
return _colorChanged;
179183
}

src/CheerLights.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class CheerLights {
5151
char _colorName[32];
5252
uint32_t _colorHex;
5353
uint32_t _previousColorHex;
54+
bool _colorChanged;
5455
};
5556

5657
#endif // CHEERLIGHTS_H

0 commit comments

Comments
 (0)