Hello all,
I am working on a project which make leds blinking, based on a scenario. Attiny85 used.
I've created a stSequence which works nice, but I have some issues depending on the duration of the sequence.
Below, you can see a 1mn, 2mn and 6mn program.
During that program, the leds are turned on progressively, then blink 4 times.
1mn and 2mn works fine but not 6mn. That makes me think that "tempsprog" is getting a too high value, and the Attiny85 does not work properly.
During the 6mn program, the leds are turned on progressively, but do not blink. They stay ON until I power off the board...
int fadeAmount = 1;
int puissance =0;
int ledPin =0;
int tempsprog = 0;
unsigned long time_now = 0;
typedef struct
{
int initA;
int delay1; //temps en ms pour atteindre
int target1;
int delay2;
int montee;
} ST_SEQUENCE;
void setup() {
pinMode(ledPin, OUTPUT);
}
void(* resetFunc) (void) = 0;
void arret()
{
delay(1000);
resetFunc();
}
void loop() {
//analogWrite(ledPin, 190);
if(digitalRead(A1)==HIGH) //1 mn
{
tempsprog=4600+(7500*1); //(ajouter 7500*nbminutes supplémentaires : exemple --> 1 mn = 4700 ; 2 mn = 4700 + 7500; 20 mn = 4700 + 19*7500))
puissance=190;
scenario2();
}
if(digitalRead(A2)==HIGH) //2 mn
{
tempsprog=4600+(7500*2);
puissance=190;
scenario2();
}
if(digitalRead(A3)==HIGH) //6 mn
{
tempsprog=4600+(7500*6);
puissance=190;
scenario2();
}
delay(10);
}
void scenario2() {
delay(500);
ST_SEQUENCE stSequence[] = {
{10, 1000, puissance, 0,20}
, {puissance, tempsprog, puissance, tempsprog,0} // Starting scenario
, {0, 500, puissance, 500,0}
, {0, 500, puissance, 500,0}
, {0, 500, puissance, 500,0}
, {0, 500, puissance, 500,0}
, {puissance, tempsprog, puissance, tempsprog,0}
, {0, 500, puissance, 500,0}
, {0, 500, puissance, 500,0}
, {0, 500, puissance, 500,0}
, {0, 500, puissance, 500,0}
, {puissance, tempsprog, puissance, tempsprog,0}
, {0, 500, puissance, 500,0}
, {0, 500, puissance, 500,0}
, {0, 500, puissance, 500,0}
, {0, 500, puissance, 500,0}
, {puissance, tempsprog, puissance, tempsprog,0}
, {0, 500, puissance, 500,0}
, {0, 500, puissance, 500,0}
, {0, 500, puissance, 500,0}
, {0, 500, puissance, 500,0}
};
for(int i = 0 ; i < sizeof(stSequence)/sizeof(stSequence[0]); i++)
{
time_now = 0;
analogWrite(ledPin, stSequence[i].initA);
while (time_now < stSequence[i].delay1)
{
time_now++;
delay(1);
if (digitalRead(A1)==HIGH || digitalRead(A2)==HIGH || digitalRead(A3)==HIGH) {
analogWrite(ledPin, 0);
arret();
}
}
while(fadeAmount < stSequence[i].target1-stSequence[i].initA){
fadeAmount++;
analogWrite(ledPin, stSequence[i].initA+fadeAmount);
time_now = 0;
while (time_now < stSequence[i].montee)
{
time_now++;
delay(1);
if (digitalRead(A1)==HIGH || digitalRead(A2)==HIGH || digitalRead(A3)==HIGH) {
analogWrite(ledPin, 0);
arret();
}
}
}
fadeAmount=0;
time_now = 0;
while (time_now < stSequence[i].delay2)
{
time_now++;
delay(1);
if (digitalRead(A1)==HIGH || digitalRead(A2)==HIGH || digitalRead(A3)==HIGH) {
analogWrite(ledPin, 0);
arret();
}
}
}
tempsprog=0;
analogWrite(ledPin, 0);
}
