Skip to content

Commit 167324b

Browse files
committed
Added Arduino UNO R4 WiFi example for its LED matrix
1 parent a6eab1b commit 167324b

File tree

2 files changed

+107
-0
lines changed

2 files changed

+107
-0
lines changed
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
'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.
3+
4+
To join the CheerLights community, visit https://cheerlights.com.
5+
*/
6+
7+
// Include the correct WiFi library based on the board
8+
#if defined(ESP8266)
9+
#include <ESP8266WiFi.h>
10+
#elif defined(ESP32)
11+
#include <WiFi.h>
12+
#elif defined(ARDUINO_SAMD_MKR1000)
13+
// For Arduino MKR1000 using WiFi101 library
14+
#include <WiFi101.h>
15+
#elif defined(ARDUINO_SAMD_MKRWIFI1010)
16+
// For Arduino MKR WiFi 1010 using WiFiNINA library
17+
#include <WiFiNINA.h>
18+
#elif defined(ARDUINO_AVR_UNO_WIFI_REV2)
19+
// For Arduino Uno WiFi Rev2
20+
#include <WiFiNINA.h>
21+
#elif defined(ARDUINO_ARCH_SAMD)
22+
// For other SAMD boards
23+
#include <WiFiNINA.h>
24+
#else
25+
#include <WiFi.h>
26+
#endif
27+
28+
// Include the CheerLights library and instantiate the CheerLights object
29+
#include <CheerLights.h>
30+
CheerLights CheerLights;
31+
32+
// Include the secrets file that contains the WiFi credentials
33+
#include "secrets.h"
34+
35+
unsigned long previousMillis = 0;
36+
const long updateInterval = 15000;
37+
38+
// Include the ArduinoGraphics library and the Arduino LED Matrix library
39+
#include "ArduinoGraphics.h"
40+
#include "Arduino_LED_Matrix.h"
41+
42+
ArduinoLEDMatrix matrix;
43+
44+
byte cheerLightsIcon[8][12] = {
45+
{ 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 },
46+
{ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 },
47+
{ 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1 },
48+
{ 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1 },
49+
{ 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1 },
50+
{ 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1 },
51+
{ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 },
52+
{ 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 }
53+
};
54+
55+
String currentColorName = "";
56+
String text = "";
57+
58+
void setup() {
59+
// Initialize serial communication
60+
Serial.begin(115200);
61+
62+
// Initialize the LED matrix
63+
matrix.begin();
64+
65+
// Initialize the CheerLights library and connect to the WiFi network
66+
CheerLights.begin(SECRET_SSID, SECRET_PASSWORD);
67+
68+
// Get the current CheerLights color and update the text
69+
CheerLights.getCurrentColor();
70+
currentColorName = CheerLights.currentColorName();
71+
text = " Connecting to CheerLights ";
72+
73+
// Display the CheerLights icon for 5 seconds
74+
matrix.renderBitmap(cheerLightsIcon, 8, 12);
75+
delay(5000);
76+
}
77+
78+
void loop() {
79+
unsigned long currentMillis = millis();
80+
81+
// Update the CheerLights color every updateInterval milliseconds
82+
if (currentMillis - previousMillis >= updateInterval) {
83+
previousMillis = currentMillis;
84+
85+
// Get the current CheerLights color and update the text if it has changed
86+
CheerLights.getCurrentColor();
87+
88+
if (CheerLights.hasColorChanged()) {
89+
currentColorName = CheerLights.currentColorName();
90+
text = " CheerLights: " + currentColorName + " ";
91+
Serial.print("CheerLights: ");
92+
Serial.println(currentColorName);
93+
}
94+
}
95+
96+
// Display the scrolling text with the current CheerLights color
97+
matrix.beginDraw();
98+
matrix.stroke(0xFFFFFFFF);
99+
matrix.textScrollSpeed(50);
100+
matrix.textFont(Font_5x7);
101+
matrix.beginText(0, 1, 0xFFFFFF);
102+
matrix.println(text.c_str());
103+
matrix.endText(SCROLL_LEFT);
104+
matrix.endDraw();
105+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#define SECRET_SSID "MySSID" // replace MySSID with your WiFi network name
2+
#define SECRET_PASSWORD "MyPassword" // replace MyPassword with your WiFi password

0 commit comments

Comments
 (0)