Hi,
leider musste ich jetzt doch feststellen, dass ein Atmega328 schnell an seine Speichergrenze kommt.
Vielleicht hat ja noch jemand einen Optimierungsansatz für mich....
Was ich aktuell ausschließen kann/möchte:
- Wechsel von Atmega 328 auch auf zB Atmega2560 (bedeutet halt neue Platine)
- Verzichten auf fertige Libraries indem man das selbst schreibt (zu sehr Laie, keine Chance)
- Verzichten auf Funktionalitäten (ungern...)
- Ich nutze bereits einen anderen Bootloader (Optiboot), der mir bereits minimal mehr Speicher als der Standard Nano Bootloader verschafft
Bei meinem Code sticht insbesondere eine Library hervor, die allein schon im Beispiel Sketch mit ca 18kb compiliert wird: GitHub - Zapalot/ArdOscForWiFlyHQ: A modified version of ArdOsc for working with the WiFlyHQ library on Arduino + GitHub - Zapalot/WiFlyHQ: WiFly RN-XV Arduino Library
Würde es etwas bringen, wenn man (sofern man programmiertechnisch in der Lage ist) alle Methoden, die man für sein Projekt nicht benötigt, aus der Library rauslöscht? Oder werden beim kompilieren sowieso nur die Methoden/Funktionen/etc. kompiliert, die auch im Sketch aufgerufen werden?
Hier mal mein aktueller Sketch, damit wir nicht nur über heiße Luft reden:
PART I:
//++++++++++++++++++++++++++++++++++++++++++++Libraries++++++++++++++++++++++++++++++++++++++++++++
#include <WiFlyHQ.h>
#include <ArdOSCForWiFlyHQ.h>
#include <DS3231.h>
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
#include <OneWire.h>
#include <DallasTemperature.h>
//++++++++++++++++++++++++++++++++++++++++++++++WIFLY++++++++++++++++++++++++++++++++++++++++++++++
char* ssid = "xxx";
char* pass = "xxx";
char* IPwifly = "x.x.x.x"; //IP Wifly Module
int Portwifly = 8000; //Touchosc: Outgoing
char* IPhost = "x.x.x.x"; //IP iPhone
int Porthost = 9000; //Touchosc: Incoming
WiFly WIFI;
OSCServer server(&WIFI); // receive
OSCClient client(&WIFI); // send
//++++++++++++++++++++++++++++++++++++++++++++++DS3231+++++++++++++++++++++++++++++++++++++++++++++
DS3231 rtc(SDA, SCL); //Address==0x68!!!
byte day_,month_,year_,hour_,min_,sec_,control_temp;
byte prevMin=0;
//+++++++++++++++++++++++++++++++++++++++++++++DS18B20+++++++++++++++++++++++++++++++++++++++++++++
#define ONE_WIRE_BUS 14
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
//++++++++++++++++++++++++++++++++++++++++++++++PCA9685++++++++++++++++++++++++++++++++++++++++++++
Adafruit_PWMServoDriver board1 = Adafruit_PWMServoDriver(0x40);
Adafruit_PWMServoDriver board2 = Adafruit_PWMServoDriver(0x41);
const byte LED[] = {7,15,6,14,0,1,2,9,10,8,12,13,11,5}; //W1+2;B1+2;RB=7;UV=6;RED=15;RGB1;RGB2;Fans
const byte Fans = 1;//?????
//PCA 0= RoyalBlue
//1=Rot
//2=UV
//6=White1
//7=Blue1
//14=Blue2
//15=White2
//8+=Green
//9+ =Red
//10+ =Blue
unsigned int valueLight[14];
unsigned int prevValueLight[14];
byte LEDmode=0;
//++++++++++++++++++++++++++++++++++++++++++RGBWHEEL+++++++++++++++++++++++++++++++++++++++++++++++++
byte RGBmode=0;
float hue=0.0, saturation=1.0, value=1.0;
long rgb[3];
long rgbval;
byte bright[3] = {100, 100, 100};
byte FactorOfWheel = 25;
//++++++++++++++++++++++++++++++++++++++++++++Platinen++++++++++++++++++++++++++++++++++++++++++++
byte Platinen=2;
byte DS18Sensoren=Platinen*2;
//++++++++++++++++++++++++++++++++++++++++++++++LightArrays++++++++++++++++++++++++++++++++++++++++++
// 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23
byte lightArray[14] [24] = { { 0, 0, 0, 0, 0, 0, 0, 20, 40, 70, 100, 100, 100, 100, 100, 100, 100, 80, 50, 30, 20, 10, 0, 10 },
{ 0, 0, 0, 0, 0, 0, 0, 20, 40, 70, 100, 100, 100, 100, 100, 100, 100, 80, 50, 30, 20, 10, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 20, 40, 70, 100, 100, 100, 100, 100, 100, 100, 80, 50, 30, 20, 10, 0, 0 },
{ 100, 0, 0, 0, 0, 0, 0, 20, 40, 70, 100, 100, 100, 100, 100, 100, 100, 80, 50, 30, 20, 10, 0, 0 },
{ 100, 0, 0, 0, 0, 0, 0, 20, 40, 70, 100, 100, 100, 100, 100, 100, 100, 80, 50, 30, 20, 10, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 20, 40, 70, 100, 100, 100, 100, 100, 100, 100, 80, 50, 30, 20, 10, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 20, 40, 70, 100, 100, 100, 100, 100, 100, 100, 80, 50, 30, 20, 10, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } };
void setup() {
//++++++++++++++++++++++++++++++++++++++++++++++WIFLY++++++++++++++++++++++++++++++++++++++++++++++
Serial.begin(115200);
WIFI.setupForUDP<HardwareSerial>(&Serial,115200,false,ssid,pass,"WiFly",IPwifly,Portwifly,IPhost,Porthost,false);
server.addCallback("/auto",&autoLED);
server.addCallback("/white",&autoWhite);
server.addCallback("/blue",&autoBlue);
server.addCallback("/royal",&autoRoyalBlue);
server.addCallback("/red",&autoRed);
server.addCallback("/purple",&autoPurple);
server.addCallback("/rgbswitch",&rgbswitch);
server.addCallback("/rgbmixer",&rgbmixer);
server.addCallback("/factor",&wheelFactor);
server.addCallback("/rgb0",&rgbValue0);
server.addCallback("/rgb1",&rgbValue1);
server.addCallback("/rgb2",&rgbValue2);
server.addCallback("/brightness0",&rgbBrightness0);
server.addCallback("/brightness1",&rgbBrightness1);
server.addCallback("/brightness2",&rgbBrightness2);
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
//++++++++++++++++++++++++++++++++++++++++++++++RTC+++++++++++++++++++++++++++++++++++++++++++++
rtc.begin();
//setTime(21,22,20,29,10,14);
//++++++++++++++++++++++++++++++++++++++++++++++PCA9685+++++++++++++++++++++++++++++++++++++++++++++
board1.begin();
board1.setPWMFreq(800);
//uint8_t twbrbackup = TWBR;
//TWBR = 12;
for (int i=0;i<13;i++) board1.setPWM(LED[i], 0, 0);
//++++++++++++++++++++++++++++++++++++++++++RGBWHEEL+++++++++++++++++++++++++++++++++++++++++++++++++
byte RGBmode=0;
float hue=0.0, saturation=1.0, value=1.0;
long rgb[3];
long rgbval;
long bright[3] = {100, 100, 100}; ///ansteuern????
//++++++++++++++++++++++++++++++++++++++++++DS18B20+++++++++++++++++++++++++++++++++++++++++++++++++
sensors.begin();
}
void loop() {
getTimeAndTemp(rtc.getTime());
if (server.availableCheck(2)>0){}
// if (LEDmode==0) getLight();
// if (LEDmode==2) dimLED();
}
//++++++++++++++++++++++++++++++++++++++++++LIGHT++++++++++++++++++++++++++++++++++++++++++++++++
void getLight() {
for (int i=0; i<14; i++) {
if (hour_<23) valueLight[i] = fadeLight(min_, sec_, map(lightArray[i][hour_+1],0,100,0,4095), map(lightArray[i][hour_],0,100,0,4095));
else if (hour_==23) valueLight[i] = fadeLight(min_, sec_, map(lightArray[i][0],0,100,0,4095), map(lightArray[i][hour_],0,100,0,4095));
if (prevValueLight[i] != valueLight[i]) {
board1.setPWM(LED[i], 0, valueLight[i]);
prevValueLight[i] = valueLight[i];
}
}
}
int fadeLight(byte mm, byte ss, const int PWMvalueSoon, const int PWMvalueNow) {
float bruch = (float)3600 / (PWMvalueSoon - PWMvalueNow);
int result;
result = PWMvalueNow + ((3600 - (3600 - ((mm * 60) + (ss * 1)))) / bruch);
return result;
}
void dimLED() {
for (int i=0; i<14; i++) board1.setPWM(LED[i], 0, 1000);
}