I'm a painful 128 bytes of my max for this Trinket. Any refactoring I could do to get down the size?
#include <Adafruit_NeoPixel.h>
#include <Wire.h>
#include <RTClib.h>
#define LEDPIN 1
#define TONE 4
#define BTNPIN 3
RTC_DS1307 rtc;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(5, LEDPIN, NEO_RGB);
const long fadeTime = 10 * 60000L; // X minutes
const int colorStops = 255;
const int delaySpeed = fadeTime / colorStops;
const int notes[] = {262,294,330,349};
const uint32_t alarmLength = 5 * 60000L; // 5 minutes
void setup() {
rtc.begin();
rtc.adjust(DateTime(__DATE__, __TIME__));
pinMode(TONE,OUTPUT);
pinMode(BTNPIN, INPUT);
digitalWrite(BTNPIN, HIGH);
strip.begin();
strip.show();
}
void loop() {
DateTime now = rtc.now();
// If it's 5:10 am on a week day, start the fade in
if (now.hour() == 5 && now.minute() == 10 && now.second() == 0 && now.dayOfTheWeek() != 1 && now.dayOfTheWeek() != 7){
// Fade in light
for(int i = 1; i<colorStops; i++){
if (kill() == true){ break; }
for(int np = 0;np<strip.numPixels(); np++){
strip.setPixelColor(np, strip.Color(i,i,i));
}
strip.show();
delay(delaySpeed);
}
// Play tone after light fully bright
for( uint32_t tStart = millis(); (millis()-tStart) < alarmLength; ){
if (kill() == true){ break; }
for(int np = 0;np<strip.numPixels(); np++){
strip.setPixelColor(np, strip.Color(random(50,255),random(50,255),random(50,255)));
}
strip.show();
beep(notes[random(0,3)]);
delay(100);
}
turnOffPixels();
}
}
void beep(int delayAmount)
{
for (uint16_t t = 0; t < 30*1000/2; t += delayAmount)
{
digitalWrite(TONE,HIGH);
delayMicroseconds(delayAmount);
digitalWrite(TONE,LOW);
delayMicroseconds(delayAmount);
}
}
void turnOffPixels() {
for(int np = 0;np<strip.numPixels(); np++){
strip.setPixelColor(np, strip.Color(0,0,0));
}
strip.show();
}
bool kill() {
if (! digitalRead(BTNPIN)) {
turnOffPixels();
return true;
} else {
return false;
}
}
Error...
Sketch uses 5,438 bytes (102%) of program storage space. Maximum is 5,310 bytes.
Global variables use 97 bytes of dynamic memory.