Hi,
I am quite new to Teensy and this is my first project with one.
I have started writing a simple light controller but am dismayed to find that after writing less than half of my code, I am completely and utterly out of space.
I can't see why my code would be using so much space. I am not using serial, nor am I using any strings.
I am using 3 libraries but they seem like they should be small and simple.
Can anyone lend me any ideas of where I should be looking to trim space? What tools do I have to see where all my space is going?
Here is the build error:
Here is my complete code:
I am quite new to Teensy and this is my first project with one.
I have started writing a simple light controller but am dismayed to find that after writing less than half of my code, I am completely and utterly out of space.
I can't see why my code would be using so much space. I am not using serial, nor am I using any strings.
I am using 3 libraries but they seem like they should be small and simple.
Can anyone lend me any ideas of where I should be looking to trim space? What tools do I have to see where all my space is going?
Here is the build error:
Code:
c:/program files (x86)/arduino/hardware/tools/arm/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/bin/ld.exe: region `FLASH' overflowed by 114472 bytes
Here is my complete code:
Code:
#include <RGBLed.h>
#include <EasyButton.h>
#include <StateMachine.h>
////////////////////////////
// Adjust parameters here:
////////////////////////////
const unsigned long startMins = 30;
const unsigned long endMins = 180;
const unsigned long fadeupTimeSecs = 10;
const unsigned long fadedownTimeMins = 30;
////////////////////////////
const unsigned long rangeMins = endMins - startMins;
const unsigned long fadeupTimeMillis = fadeupTimeSecs * 1000;
#define RED_PIN 16
#define GREEN_PIN 17
#define BLUE_PIN 20
#define LED_PIN 13
#define SSR_PIN 23
#define SWTest_PIN 14
#define SWNext_PIN 15
#define Day_PIN 21
RGBLed LED(RED_PIN, GREEN_PIN, BLUE_PIN, RGBLed::COMMON_CATHODE);
EasyButton nextButton(SWNext_PIN, 40, false, true);
EasyButton testButton(SWTest_PIN, 40, false, true);
StateMachine machine = StateMachine();
State* S0_daytime = machine.addState(&daytime_0);
State* S1_fadeUp = machine.addState(&fadeUp_1);
State* S2_lightsOn = machine.addState(&lightsOn_2);
State* S3_fadeDown = machine.addState(&fadeDown_3);
State* S4_nighttime = machine.addState(&nighttime_4);
unsigned long fadeupTimeStamp = 0;
////// Functions to process each of the states //////
void daytime_0(){
if(machine.executeOnce){
LED.setColor(RGBLed::RED);
}
if (readDaylight() == LOW) {
machine.transitionTo(S1_fadeUp);
}
}
void fadeUp_1(){
if(machine.executeOnce){
fadeupTimeStamp = millis();
digitalWrite(SSR_PIN, LOW); // Turn on SSR
LED.setColor(RGBLed::YELLOW);
}
unsigned long dur = millis() - fadeupTimeStamp;
float fadeVal = float(dur)/float(fadeupTimeMillis);
if (fadeVal >= 1.0) {
machine.transitionTo(S2_lightsOn);
} else {
int lampVal = int(pow(fadeVal, 2.4) * 1024);
analogWrite(A12, lampVal);
}
}
void lightsOn_2(){
if(machine.executeOnce){
LED.setColor(RGBLed::GREEN);
}
}
void fadeDown_3(){
if(machine.executeOnce){
LED.setColor(RGBLed::CYAN);
}
}
void nighttime_4(){
if(machine.executeOnce){
LED.setColor(RGBLed::BLUE);
}
}
/////// End of state functions /////////
void nextState() {
machine.transitionTo((machine.currentState + 1) % 5);
}
int readPot() {
int potVal = analogRead(A8);
float amt = 1.0 - (float(potVal) / 1023.0);
int mins = int((rangeMins * amt)) + startMins;
return mins;
}
bool readDaylight(){
return !(digitalRead(Day_PIN) == LOW);
}
void setup() {
pinMode(SSR_PIN, OUTPUT);
pinMode(LED_PIN, OUTPUT);
pinMode(Day_PIN, INPUT);
digitalWrite(LED_PIN, HIGH);
digitalWrite(SSR_PIN, HIGH);
LED.setColor(RGBLed::RED);
nextButton.begin();
testButton.begin();
nextButton.onPressed(nextState);
}
void loop() {
machine.run();
nextButton.read();
}