diff --git a/examples/CheerLights_UNO_R4_WiFi_LED_Matrix/CheerLights_UNO_R4_WiFi_LED_Matrix.ino b/examples/CheerLights_UNO_R4_WiFi_LED_Matrix/CheerLights_UNO_R4_WiFi_LED_Matrix.ino new file mode 100644 index 0000000..e47c7da --- /dev/null +++ b/examples/CheerLights_UNO_R4_WiFi_LED_Matrix/CheerLights_UNO_R4_WiFi_LED_Matrix.ino @@ -0,0 +1,105 @@ +/* +'CheerLights_UNO_R4_WiFi_LED_Matrix' example demonstrates how to use the CheerLights Arduino library to fetch and display the current CheerLights color on an LED matrix on the Arduino Uno R4 WiFi. + +To join the CheerLights community, visit https://cheerlights.com. +*/ + +// Include the correct WiFi library based on the board +#if defined(ESP8266) + #include +#elif defined(ESP32) + #include +#elif defined(ARDUINO_SAMD_MKR1000) + // For Arduino MKR1000 using WiFi101 library + #include +#elif defined(ARDUINO_SAMD_MKRWIFI1010) + // For Arduino MKR WiFi 1010 using WiFiNINA library + #include +#elif defined(ARDUINO_AVR_UNO_WIFI_REV2) + // For Arduino Uno WiFi Rev2 + #include +#elif defined(ARDUINO_ARCH_SAMD) + // For other SAMD boards + #include +#else + #include +#endif + +// Include the CheerLights library and instantiate the CheerLights object +#include +CheerLights CheerLights; + +// Include the secrets file that contains the WiFi credentials +#include "secrets.h" + +unsigned long previousMillis = 0; +const long updateInterval = 15000; + +// Include the ArduinoGraphics library and the Arduino LED Matrix library +#include "ArduinoGraphics.h" +#include "Arduino_LED_Matrix.h" + +ArduinoLEDMatrix matrix; + +byte cheerLightsIcon[8][12] = { + { 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 }, + { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 }, + { 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1 }, + { 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1 }, + { 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1 }, + { 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1 }, + { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 }, + { 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 } +}; + +String currentColorName = ""; +String text = ""; + +void setup() { + // Initialize serial communication + Serial.begin(115200); + + // Initialize the LED matrix + matrix.begin(); + + // Initialize the CheerLights library and connect to the WiFi network + CheerLights.begin(SECRET_SSID, SECRET_PASSWORD); + + // Get the current CheerLights color and update the text + CheerLights.getCurrentColor(); + currentColorName = CheerLights.currentColorName(); + text = " Connecting to CheerLights "; + + // Display the CheerLights icon for 5 seconds + matrix.renderBitmap(cheerLightsIcon, 8, 12); + delay(5000); +} + +void loop() { + unsigned long currentMillis = millis(); + + // Update the CheerLights color every updateInterval milliseconds + if (currentMillis - previousMillis >= updateInterval) { + previousMillis = currentMillis; + + // Get the current CheerLights color and update the text if it has changed + CheerLights.getCurrentColor(); + + if (CheerLights.hasColorChanged()) { + currentColorName = CheerLights.currentColorName(); + text = " CheerLights: " + currentColorName + " "; + Serial.print("CheerLights: "); + Serial.println(currentColorName); + } + } + + // Display the scrolling text with the current CheerLights color + matrix.beginDraw(); + matrix.stroke(0xFFFFFFFF); + matrix.textScrollSpeed(50); + matrix.textFont(Font_5x7); + matrix.beginText(0, 1, 0xFFFFFF); + matrix.println(text.c_str()); + matrix.endText(SCROLL_LEFT); + matrix.endDraw(); +} diff --git a/examples/CheerLights_UNO_R4_WiFi_LED_Matrix/secrets.h b/examples/CheerLights_UNO_R4_WiFi_LED_Matrix/secrets.h new file mode 100644 index 0000000..00bfead --- /dev/null +++ b/examples/CheerLights_UNO_R4_WiFi_LED_Matrix/secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "MySSID" // replace MySSID with your WiFi network name +#define SECRET_PASSWORD "MyPassword" // replace MyPassword with your WiFi password \ No newline at end of file