#include <SPI.h>
#include "sr595.h"
#define DIV 5
#define SIZE_OF(a) (sizeof(a) / sizeof(a[0]))
const byte PIN_CS = 4;
SR59532 sr32(PIN_CS);
struct OutTime {
uint32_t dataOut;
uint32_t time;
};
OutTime outTimeList[] = {
{ 0x864921, 30000UL / DIV }, // green
{ 0x864922, 3000UL / DIV }, // yellow
{ 0x864924, 1000UL / DIV }, // red
{ 0x86130C, 25000UL / DIV }, // green
{ 0x861514, 3000UL / DIV },
{ 0x861924, 1000UL / DIV },
{ 0x249924, 15000UL / DIV },
{ 0x491924, 3000UL / DIV },
{ 0x921924, 1000UL / DIV },
{ 0x921864, 30000UL / DIV },
{ 0x9228A4, 3000UL / DIV },
{ 0x924924, 1000UL / DIV } // red
};
//OutTime *outPtr = outTimeList;
OutTime *outPtr = nullptr;
uint8_t nMaxIdx = SIZE_OF(outTimeList);
OutTime *sot = nullptr;
uint8_t idx = 0;
uint32_t saveMillis;
uint8_t phaseCnt = 1;
void exec(OutTime *ot, uint8_t nMax) {
if (sot == nullptr) {
sot = &ot[idx];
sr32.write(sot->dataOut);
saveMillis = millis();
if (idx % 3 == 0) {
Serial.print("phase: ");
Serial.println(phaseCnt);
phaseCnt++;
}
Serial.println(sot->time);
} else if (millis() - saveMillis >= sot->time) {
sot = nullptr;
idx++;
if (idx == nMaxIdx) {
Serial.println("ciclo completato");
phaseCnt = 1;
}
idx = idx % nMax;
}
}
void setup() {
Serial.begin(115200);
Serial.println(sizeof(outTimeList));
outPtr = (OutTime*)malloc(sizeof(outTimeList));
memcpy(outPtr, outTimeList, sizeof(outTimeList));
pinMode(PIN_CS, OUTPUT);
digitalWrite(PIN_CS, HIGH);
SPI.begin();
sr32.write(0x924924);
delay(2000);
}
void loop() {
exec(outPtr, nMaxIdx);
}
lss0
id=0
lss1
id=1
lss3
id=3
lss2
id=2
LS0
LS1
LS2
LS3
LS4
LS5
LS6
LS7
LS8
LS9
lss4
lss5
lss7
lss6
______________
--------------------------------------------
--------------------------------------------
____________________________________
--------------------------------------------
--------------------------------------------
- - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - -
p5
p4
p6
p7
____________________________________
____________________________________
____________________________________
______________
______________
______________
______________
______________
______________
______________
______________
______________
______________
______________
______________
______________
______________
______________
______________
______________
______________
______________
______________
______________
______________
______________
______________
______________
______________
______________
______________
______________
______________
______________
______________
______________
______________
______________