D:\Arduino\WS2812B_NeoPixel_Alarm_Clock_3\WS2812B_NeoPixel_Alarm_Clock_3.ino:1:10: fatal error: Wire.h: No such file or directory
#include <WiFi.h>
^~~~~~~~
compilation terminated.
exit status 1
Compilation error: Wire.h: No such file or directory
#include <Wire.h>
#include <RTClib.h>
#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
#define DATA_PIN 6
#define INTERRUPT_PIN 2 // Pin 2 supports external interrupts on Uno R4
RTC_DS3231 rtc;
// Matrix configuration: 32 columns wide, 8 rows high
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(32, 8, DATA_PIN,
NEO_MATRIX_TOP + NEO_MATRIX_LEFT +
NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG,
NEO_GRB + NEO_KHZ800);
// Interrupt control variables
volatile bool buttonPressed = false;
unsigned long lastDebounceTime = 0;
const unsigned long debounceDelay = 250;
// Your custom scrolling text message
const String scrollMessage = "ALARM TRIGGERED! EMERGENCY ALERT!";
void setup() {
Serial.begin(9600);
pinMode(INTERRUPT_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(INTERRUPT_PIN), buttonISR, FALLING);
if (!rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (rtc.lostPower()) {
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
matrix.begin();
matrix.setTextWrap(false);
matrix.setBrightness(30);
}
void loop() {
// Check if the interrupt flag was set by a button press
if (buttonPressed) {
buttonPressed = false;
scrollTextMessage(scrollMessage);
}
// Standard Clock Mode
DateTime now = rtc.now();
int hour24 = now.hour();
int minute = now.minute();
int second = now.second(); // Fetch current second for the blink state
bool isPM = (hour24 >= 12);
int hour12 = hour24 % 12;
if (hour12 == 0) hour12 = 12;
// Determine if colon should show (true on even seconds, false on odd seconds)
bool showColon = (second % 2 == 0);
displayTime(hour12, minute, isPM, showColon);
delay(50); // Tight loop delay ensures instant button response
}
void displayTime(int h, int m, bool pm, bool showColon) {
matrix.fillScreen(0);
matrix.setCursor(0, 0);
matrix.setTextColor(matrix.Color(0, 255, 100)); // Green text
// Format hour with leading space if less than 10
String hourStr = (h < 10) ? " " + String(h) : String(h);
// Choose separating character based on showColon state
String separator = showColon ? ":" : " ";
String timeStr = hourStr + separator + (m < 10 ? "0" : "") + String(m);
matrix.print(timeStr);
// AM/PM Dot
uint16_t amPmColor = pm ? matrix.Color(255, 0, 0) : matrix.Color(0, 0, 255);
matrix.drawPixel(31, 7, amPmColor);
matrix.show();
}
// The Interrupt Service Routine (ISR)
void buttonISR() {
unsigned long currentTime = millis();
if ((currentTime - lastDebounceTime) > debounceDelay) {
buttonPressed = true;
lastDebounceTime = currentTime;
}
}
// Blocking loop function that scrolls text cleanly exactly once
void scrollTextMessage(String text) {
int messagePixelWidth = text.length() * 6;
for (int x = 32; x >= -messagePixelWidth; x--) {
matrix.fillScreen(0);
matrix.setCursor(x, 0);
matrix.setTextColor(matrix.Color(255, 255, 0)); // Yellow scrolling text
matrix.print(text);
matrix.show();
delay(40); // Controls the speed of the scroll
if (buttonPressed) {
buttonPressed = false; // Clear accidental double triggers during scroll
}
}
}
This one works
#include <Wire.h>
#include <RTClib.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
// --- PIN DEFINITIONS ---
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
#define SCREEN_ADDRESS 0x3C // Change to 0x3D if your OLED uses that address
#define BUZZER_PIN 8
#define BTN_SET 2
#define BTN_DISMISS 3
// --- OBJECT INITIALIZATION ---
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
RTC_DS3231 rtc;
// --- STATE VARIABLES ---
char daysOfTheWeek[7][12] = {
" Sunday", " Monday", " Tuesday", "Wednesday", "Thursday", " Friday", "Saturday"
};
int year=0;
int hour=0;
int hourNow=0;
int yearNow=0;
char datestr[10];
void setup() {
Serial.begin(115200);
/* // Use internal pull-ups for buttons (Active LOW)
pinMode(BTN_SET, INPUT_PULLUP);
pinMode(BTN_DISMISS, INPUT_PULLUP);
*/
// 1. Initialize OLED with error handling
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Halt execution
}
display.clearDisplay();
display.setTextColor(SSD1306_WHITE);
display.setTextSize(2);
display.setCursor(0, 10);
display.println("Booting...");
display.display();
// 2. Initialize RTC with error handling
if (!rtc.begin()) {
Serial.println(F("Couldn't find RTC on I2C bus"));
display.clearDisplay();
display.setCursor(0,0);
display.println("RTC FAIL");
display.display();
for(;;); // Halt execution
}
// 3. Check for power loss and set compile-time if needed
if (rtc.lostPower()) {
Serial.println(F("RTC lost power, setting to compile time."));
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
}
void loop() {
//display.print ("IOK");
//display.display();
DateTime now = rtc.now();
display.clearDisplay();
// --- DISPLAY LOGIC ---
// Display Time
display.setTextSize(2);
display.setCursor(15, 5);
hourNow=now.hour();
if (hourNow > 12) {
hourNow=(now.hour()-12);
}
if(hourNow < 10) display.print(' ');
display.print(hourNow);
display.print(':');
if(now.minute() < 10) display.print('0');
display.print(now.minute());
if(now.hour() < 11) {
display.print(" AM");
}
else {
display.print(" PM");
}
// Display Day of the week
display.setTextSize(2);
display.setCursor(18, 25);
display.println(daysOfTheWeek[now.dayOfTheWeek()]);
// display.display();
// Display Date
/*
display.setTextSize(2);
display.setCursor(18, 45);
sprintf(datestr, "%02d/%02d/%02d", now.day(), now.month(), now.year());
display.print(datestr);
*/
display.setTextSize(2);
display.setCursor(20, 45);
if(now.day() < 10) display.print(' ');
display.print(now.day());
display.print('/');
if(now.month() < 10) display.print(' ');
display.print(now.month());
display.display();
display.print('/');
yearNow=(now.year()-2000);
display.print(yearNow);
display.display();
display.print(' ');
display.display();
delay (1000);
}