Hallo Leute,
ich habe ein ziemlich komisches Problem. Und zwar habe ich einen QlockTwo Nachbau (schon fertig in der Hardware :-)) aber beim Programm hängts noch. Der Arduino bleibt zwischen durch einfach "stehen".Mal nach 3 Stunden mal nach 8 Stunden mal nach 1 Stunde und das immer an verschieden stellen im Programm. Er reagiert nicht mehr auf Button eingaben. Die Heartbeat LED bleibt auch aus (RTC Implus eines DS1308).
Die "LED-Ausgabe" erfolgt über die SPI-Schnitstelle an die beiden MAX7221. Die Probleme tauchen nur im Setmode=0 auf also der Normalen Zeitausgabe über die LED register. Im Sekundenmodus (setmode=1)bleibt der Ardu am leben.
Ich verwende eine modifizierte MAX7219+7221 Lib aus dem Playground die ich zum echten SPI geändert habe damit ich schneller auf MAX schreiben kann. Wie verhält es sich mit dem RAM wenn aus der Loop einzelnen Funktionen (hier voids also ohne Rückgabewerte) aufruft und es dann irgendwann zuviele werden. Kann man den Ram irgenwie nach dem ablauf einer Loop clearen.
Ich habe es jetzt mit dem org AVR WatchDogTimer gelöst aber das ist nicht die Ursache und ich würde gerne ein Lösung haben.
Hier meine Tabs.
1/3
Main Loop
/*
Enhanced and modify by Daniel Herr (adruino Forum "volvodani")
Copy of the Biegert&Funk QlockTwo reprogramming by volvodani.
The LEDs Controled by 2*MAX7221 (Daisy Chained)(over SPI).
I enhanced the LEDControl.h Libary to real SPI for the maxx7221 and renamed LEDControlSPI.h
based on:
Copyright 2011 Michael Stebbins
http://students.washington.edu/mikesteb/projects/Qlock_LED_Clock/Qlock_LED_clock.html
*/
#include <SPI.h>
#include <Wire.h>
#include <LedControlSPI.h>
#include <avr/wdt.h>
#define RTC_ADDRESS 0x68 // I2C Address of RTC
#define LCCS 10 // MAX7221 ChipSelect
#define TASTER 8 // Button Pin
#define RTCIN 2 // SQW Output of RTC connected here
#define TIME 750 // Split time between short and lognpress
LedControl LC=LedControl(LCCS,2); // Init two MAX 7221 via Real SPI (SPI Interface on Atmega 13,12,
unsigned long ptime;
unsigned long start;
boolean druck=false;
boolean ldruck=true;
boolean longpress=false;
boolean shortpress=false;
boolean tasterlesen=true;
boolean update,last=true;
boolean sec=false;
boolean lsec=false;
boolean save,one=false;
byte setmode,lm=0; // 0=Normal 1=Display Seconds 2=Set minutes 3=Set hours
byte lCase=0;
byte ss,mm,lmm,hh,mmset,lmmset,hhset,lhhset,mm5er,mm5erRest=0; // Save Variables for time
void setup() {
wdt_enable(WDTO_2S);
pinMode(RTCIN,INPUT); // SQW Output of RTC connected here
pinMode(TASTER,INPUT); // Taster Eingang
pinMode(5,OUTPUT); // LED Heartbeat of RTC Pulse
digitalWrite (TASTER,HIGH); // internal Pullup
Wire.begin(); // Start I2C Kommunikation
Wire.beginTransmission(RTC_ADDRESS); // Beginn Kommunikation auf Adresse 0x68
Wire.send(0x07); // Pointer auf Control Register 0x07
Wire.send(0x10); // Controlbyte for RTC to set the sqw Output to 1Hz
Wire.endTransmission(); // Beenden der I2C Kommunitkation
LC.shutdown(0,false); // Disable Standby of the first MAX
LC.shutdown(1,false); // Disable Standby of the first MAX
LC.setIntensity(0,15); // Brightness on max (0-15 on MAX 7221) (0-31 on MAX7219)
LC.setIntensity(1,15); // Brightness on max (0-15 on MAX 7221) (0-31 on MAX7219)
//Alle_An(); // Test All LEDS turnes on
//delay(1500); // wait 3 seconds
update=true;
TimeRead();
}
// Start Main Loop
void loop() {
wdt_reset();
/*=>Routine OneButton Control<=*/
druck=digitalRead(TASTER);
if (druck==false&&ldruck==true){
start=millis();
ldruck=false;
}
if (druck==true&&ldruck==false){
ptime=millis()-start;
ldruck=true;
}
if (ptime>=TIME){
longpress=true;
ptime=0;
//Serialprintln("LONG");
}
if (ptime<TIME&&ptime>=100) {
shortpress=true;
ptime=0;
//Serialprintln("SHORT");
}
/*One Button End*/
if (longpress==true){
setmode++;
if (setmode==2){
hhset=hh;
}
if (setmode==3){
ss=0;
mmset=mm;
}
if (setmode==4){
if(save==true){
hh=hhset;
mm=mmset;
ss=0;
RTC_Set();
save=false;
update=true;
}
setmode=0;
}
longpress=false;
one=false;
}
if(shortpress==true){
if(setmode==2){
hhset=hhset+1;
if (hhset>=24){
hhset=0;
}
}
if (setmode==3){
mmset=mmset+1;
if (mmset>=60){
mmset=0;
}
}
if (setmode<2){
if (setmode==1&&lm==true){
setmode=0;
update=true;
lm=false;
}
if (setmode==0&&lm==true){
setmode=1;
lm=false;
update=true;
}
}
lm=true;
shortpress=false;
}
sec=digitalRead(RTCIN);
digitalWrite(5,sec);
if (sec==true && lsec==false){
++ss; // sekunden Zähler aufadieren
if (ss==60){
ss=0;
mm=mm+1;
}
if (setmode==1){
LED_CLEAR();
print_numbers(ss);
}
lsec=true;
}
if (setmode==0){
if(mm!=lmm||update==true){
TimeRead();
update=false;
mm5erRest=mm%5;
mm5er=mm-mm5erRest;
update==false;
if (hh>=13){
hh=hh-12;
}
LED_CLEAR();
if (mm5erRest==1) P_EINS();
else if (mm5erRest==2) P_ZWEI();
else if (mm5erRest==3) P_DREI();
else if (mm5erRest==4) P_VIER();
W_ESIST();
if (mm5er==5||mm5er==25||mm5er==35||mm5er==55){
M_FUENF();
}
if (mm5er==10||mm5er==50){
M_ZEHN();
}
if (mm5er==15||mm5er==45){
M_VIERTEL();
}
if (mm5er==20||mm5er==40){
M_ZWANZIG();
}
if (mm5er==25||mm5er==30||mm5er==35){
M_HALB();
}
if (mm5er==0){
W_UHR();
}
if (mm5er==5||mm5er==10||mm5er==15||mm5er==20||mm5er==35){
W_NACH();
}
if (mm5er==25||mm5er==40||mm5er==45||mm5er==50||mm5er==55){
W_VOR();
}
if (mm>=25){
if (hh==12){
hh=1;
}
else
hh=hh+1;
}
if (hh==1&&mm5er==0) H_EIN();
else if (hh==1) H_EINS();
else if (hh==2) H_ZWEI();
else if (hh==3) H_DREI();
else if (hh==4) H_VIER();
else if (hh==5) H_FUENF();
else if (hh==6) H_SECHS();
else if (hh==7) H_SIEBEN();
else if (hh==8) H_ACHT();
else if (hh==9) H_NEUN();
else if (hh==10) H_ZEHN();
else if (hh==11) H_ELF();
else if (hh==12||hh==0) H_ZWOELF();
}
lmm=mm;
}
if (sec==false && lsec==true){
lsec=false;
}
if (setmode==2){
if (hhset!=lhhset||one==false){
LED_CLEAR();
print_numbers(hhset);
LC.setLed(0,5,0,true); // top left
LC.setLed(1,5,0,true); // bottom left
lhhset=hhset;
one=true;
save=true;
}
}
if (setmode==3){
if (mmset!=lmmset||one==false){
LED_CLEAR();
print_numbers(mmset);
LC.setLed(0,5,7,true); // top right
LC.setLed(1,5,7,true);// bottom right
lmmset=mmset;
one=true;
save=true;
}
}
}
// End Main Loop
void print_numbers(byte num){ // Funktion zum Dartellen von Dezimalzahlen auf der Matrix
byte num10;
byte num1;
num1=num%10;
num10=(num-num1)/10;
switch (num10){
case 0:
L_ZERO();
break;
case 1:
L_ONE();
break;
case 2:
L_TWO();
break;
case 3:
L_THREE();
break;
case 4:
L_FOUR();
break;
case 5:
L_FIVE();
break;
}
switch (num1){
case 0:
R_ZERO();
break;
case 1:
R_ONE();
break;
case 2:
R_TWO();
break;
case 3:
R_THREE();
break;
case 4:
R_FOUR();
break;
case 5:
R_FIVE();
break;
case 6:
R_SIX();
break;
case 7:
R_SEVEN();
break;
case 8:
R_EIGHT();
break;
case 9:
R_NINE();
break;
}
}