I am a beginner to Ardunino UNO This is my first program to light up an LED strip
#include <Adafruit_NeoPixel.h>
#include <RTCZero.h>
#define PIN 6
#define NUMPIXELS 60 // Define the total number of pixels in your strip
#define BRIGHTNESS 50 // Adjust the brightness (0-255)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
RTCZero rtc;
void setup() {
strip.begin(); // Intializes the neo pixel library for use
strip.show(); // Initialize all pixels to 'off'
rtc.begin();
// Intialzes the real time clock , the rtc is defined previuosly ,the dot access the the memebr in this case begin () , which is a method , method is used to perform an action , they belong to a class and defines how an object behaves
// Set the initial time at the time of the project
rtc.setHours(12);
rtc.setMinutes(0);
rtc.setSeconds(0);
}
void loop() {
int currentHour = rtc.getHours(); // Get the current hour from the real time clock
uint32_t color;
// Set color based on the time of the day
if (currentHour >= 6 && currentHour < 16) {
// Yellow during 6 am to 4 pm
color = strip.Color(255, 255, 0);
} else if (currentHour >= 16 && currentHour < 20) {
// Orange during 4 pm to 8 pm
color = strip.Color(255, 165, 0);
} else {
// Blue during 8 pm to 6 am
color = strip.Color(0, 0, 255);
}
// Set the color for all pixels
fillStrip(color);
// Optional: Adjust brightness
strip.setBrightness(BRIGHTNESS);
// Update the NeoPixel strip
strip.show();
// Delay to avoid updating the colors too frequently
delay(60000); // Delay for 1 minute (adjust as needed)
}
// Uses for loop to itrate the color for all the pixels in the led strip
void fillStrip(uint32_t color) {
for (int i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, color);
}
}
Unable to compile the program due to the below error. How do I find an equivalent function for Arduino UNO ??
WARNING: library RTCZero claims to run on samd architecture(s) and may be incompatible with your current board which runs on avr architecture(s).
-
1The RTCZero library is meant to control the RTC peripheral embedded in some Arduinos. The Uno does not have an embedded RTC, so there can be no equivalent.Edgar Bonet– Edgar Bonet12/12/2023 19:38:13Commented Dec 12, 2023 at 19:38
1 Answer 1
There is no built in RTC on a normal Arduino UNO. If you want to do the same thing on an UNO you can either add an external RTC module like the DS3231 or the DS1307. There are libraries in the library manager for those devices that will work with your UNO. You can then find the functions that perform the same job as the ones in your code and replace them.
If your UNO is the new UNO-R4, then yes those do have an RTC and there is a library in the core for it, but the RTC on those boards is terribly inaccurate due to the lack of an accurate clock source to drive it. So even in that case I'd still recommend an external RTC.