Hey guys,
I'm having a difficult time trying to reduce the used space of my sketch. I'm lacking 300bytes of storage space.
Any ideas?
//#include <DigisparkOLED.h>
#include <TinyWireM.h>
#include <Tiny4kOLED.h>
//#include <Wire.h>
#include <EnableInterrupt.h>
#include <EEPROMex.h>
volatile int CurrentTime;
volatile int hallPin = 3;
volatile int modus;
volatile int StartTime;
volatile double velocity [10];
volatile float staytime;
volatile float staystart;
volatile double reifenumfang = 2330; //in mm
volatile double maxvelocity;
volatile double mileage;
volatile double deltamileage;
volatile double cache;
volatile boolean iszero=false;
volatile float timeelapsed;
#define INTERRUPTEDPIN 1 // == B1
const uint8_t inputBitMask = digital_pin_to_bit_mask_PGM[INTERRUPTEDPIN];
volatile uint8_t interruptState=0;
void messure(){
CurrentTime = millis();
if(iszero){
staytime+=double(millis()-staystart);
}
iszero=false;
if (digitalRead(hallPin)== LOW && CurrentTime-StartTime>0){
timeelapsed= (CurrentTime-StartTime);
StartTime = millis();
cache = (reifenumfang/timeelapsed)*3.6;
if(cache<100){
if(cache>maxvelocity){ //Updaten der Topspeed und Mileage
maxvelocity=cache;
}
mileage+=reifenumfang/1000000;
deltamileage+=reifenumfang/1000000;
for (int i=9;i>0;i--){ //Überschreiben der Werte
velocity[i]=velocity[i-1];
}
velocity[0]=cache;
}
}
}
void setup() {
DDRB &= ~inputBitMask; // INPUTPIN is set to input
PORTB |= inputBitMask; // Pull up the resistor
MCUCR &= ~PUD; // ensure Pull Up Disable is off
enableInterrupt(INTERRUPTEDPIN, messure, FALLING);
//Serial.begin(9600);
if(isnan(EEPROM.readDouble(0))){
EEPROM.writeDouble(0,0);
}
if(isnan(EEPROM.readDouble(10))){
EEPROM.writeDouble(10,0);
}
pinMode(2, INPUT);
pinMode(hallPin, INPUT);
//attachInterrupt(1,messure,FALLING);
oled.begin();
}
void loop() {
CurrentTime = millis();
if((CurrentTime-StartTime>5000)&&(!iszero)){
iszero=true;
staystart=millis();
}
if(digitalRead(2)==HIGH){
modus++;
modus=modus%2;
oled.clear(); //all black
}
displayupdate();
cache=EEPROM.readDouble(10);
if(cache<maxvelocity){
EEPROM.writeDouble(10,maxvelocity);
}
if(deltamileage>0.7){
cache=EEPROM.readDouble(0)+deltamileage;
deltamileage=0;
EEPROM.writeDouble(0,cache);
}
}
void displayupdate(){
oled.setCursor(0, 0);
oled.setFont(FONT8X16);
oled.print(velocity[0]);
}