I am using an ATTiny85 for the first time and at compile I receive the following errors
Arduino: 1.6.11 (Windows 10), Board: "Digispark (Default - 16.5mhz)"
C:\Users\Steve\AppData\Local\Temp\build129e80c0e73568918bca55047472d138.tmp/Smoke_Auto-ATtiny.ino.ino.elf section `.text' will not fit in region `text'
c:/program files (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.9.2/../../../../avr/bin/ld.exe: region `text' overflowed by 562 bytes
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compiling for board Digispark (Default - 16.5mhz).
The chip is
Atmel 1344
Tiny85
20SF
I think what is happening is that my code is too big for the board. Am I right?
Assuming so, ignoring any obvious programming errors (I can't debug for this board until I can upload :P ) how can I squeeze code like this onto an ATTiny? I am not looking for someone to rewrite it for me, I am more interested in learning where there is any obvious bloat - I suspect the IR library (IRremote Version 2.0.1 June, 2015 by Ken Shirriff : 11Kb)
FWIW this is a project to convert a manually operated smoke machine into an automatic one and be able to manipulate the smoke time and delay via a remote. It works on a Mega, proof of concept complete, I want to shrink the board to fit into the mouse-sized controller if that is possible.
#include <IRremote.h>
long smokeTimeInit = 5000; // initial smoke time
long smokeWaitInit = 60000; // initial interval between smoke
long smokeIncrement = 1000; // timer increment value
long delayIncrement = 5000; // timer increment value
unsigned long previousMillis = 0; // this is our stored time
unsigned long currentMillis; //where we keep count of time
const int smokeOnPin = 2; // output to relay
int smokeStopped = false; // flag to stop smoke
const int LED = 0;
const long RECV_PIN = 1; // input from IR receiver
IRrecv irrecv(RECV_PIN);
decode_results results;
long smokeTime = smokeTimeInit;
long smokeWait = smokeWaitInit;
void setup() {
pinMode(smokeOnPin, OUTPUT);
pinMode(LED, OUTPUT);
irrecv.enableIRIn(); // Start the receiver
digitalWrite(smokeOnPin, LOW); // start with the smoke on
digitalWrite(LED, HIGH);
}
void loop() {
if (irrecv.decode(&results)) {
switch(results.value){
case 284157975 :
//more smoke time
smokeTime = smokeTime + smokeIncrement;
smokeStopped = false; // smoke on
break;
case 284104935 :
//less smoke time
if(smokeTime > smokeIncrement){ // don't let the smoke time become less than the increment value i.e. negative
smokeTime = smokeTime - smokeIncrement;
}
else{
smokeTime = 1000;
}
smokeStopped = false;
break;
case 284125335 :
//reduce interval
if(smokeWait > delayIncrement){
smokeWait = smokeWait - delayIncrement;
}
else{
smokeWait = 1000;
}
smokeStopped = false; // smoke on
break;
case 284141655 :
// increase interval
smokeWait = smokeWait + delayIncrement;
smokeStopped = false; // smoke on
break;
case 284140125 :
// reset to initial time values
smokeTime = smokeTimeInit;
smokeWait = smokeWaitInit;
smokeStopped = false; // smoke on
break;
case 284148285 :
// reset but with shorter smoke time
smokeTime = 1000;
smokeWait = 60000;
smokeStopped = false; // smoke on
break;
case 284123805 :
// reset with short smoke and shorter interval
smokeTime = 2000;
smokeWait = 30000;
smokeStopped = false; // smoke on
break;
case 284131965 :
// stop
smokeStopped = true;
break;
}
irrecv.resume();
}
currentMillis = millis();
if(smokeStopped){ // don't even do this if smoke stopped
if (currentMillis - previousMillis >= smokeTime && digitalRead(smokeOnPin)==0) {
digitalWrite(smokeOnPin, HIGH); // turn the smoke on
digitalWrite(LED, LOW);
previousMillis = currentMillis;
}
else if (currentMillis - previousMillis >= smokeWait && digitalRead(smokeOnPin)==1 ) {
digitalWrite(smokeOnPin, LOW); // turn the smoke off
digitalWrite(LED, HIGH);
previousMillis = currentMillis;
}
}
}