Hi,
I asked a similar question a few days back, but now i could finally start code a few lines.
I want to create the electronics for a ghostbusters proton pack. I want that if a specific switch is turned on a specific i call it boot sequence gets startet.
in my code i create an enum which constist of different bootphases.
if the switch is turned on the first phase starts, after the first phase has finished the enum gets increased. then the next phase starts and so on.
the first question is, how can i reset these functions, so that if i turn the switch off and turn it back on the whole sequence starts again?
the second question is why does my code behave in this way:
- enum is set to bootPhase0,
- after exiting the first function it is set to bootPhase1
- after exiting the second function it is set to bootPhase2
- and the reset to bootPhase1 and stays at bootPhase1?? it should stay at bootPhase2 so that i can go on with the third function.
these are the functions i am using:
enum BootSequence {
bootPhase0,
bootPhase1,
bootPhase2,
bootPhase3,
};
BootSequence WandStartSequence = bootPhase0;
bool bootBlinkK = false;
void PROGRAM_BOOT_BLINK_L() {
static bool n_on = true;
static int timer1 = 3;
if (bootBlink.isCycleElapsed()) {
if (timer1 > 0) {
if (n_on) {
playerSoftware0.playSpecified(1);
DM13ALeds.setSegmentDefined(l_Segment);
} else {
DM13ALeds.clearSegment(l_Segment);
timer1--;
}
DM13ALeds.outputRefresh_direct();
n_on = !n_on;
}
if (timer1 == 0) {
bootBlinkK = true;
WandStartSequence = bootPhase1;
}
}
}
void PROGRAMM_BOOT_KL() {
static int timer = 2;
if (bootBlinkKL.isCycleElapsed()) {
switch (timer) {
case 2:
DM13ALeds.setSegmentDefined(k_Segment);
DM13ALeds.outputRefresh_direct();
break;
case 1:
DM13ALeds.setSegmentDefined(n_Segment);
DM13ALeds.outputRefresh_direct();
WandStartSequence = bootPhase2;
break;
default:
return; // Do nothing if timer is not 1 or 2
}
if (timer > 0) {
timer--;
}
}
}
void bootsequence() {
if (Switch.toggled() && Switch.read()) {
if (WandStartSequence == bootPhase0) PROGRAM_BOOT_BLINK_L();
if (WandStartSequence == bootPhase1) PROGRAMM_BOOT_KL();
[...]
}
}
this is how the loop should look like:
loop() {
bootsequence();
}
if you want i could also provide the complete code which is work in progress and has a lot of stuff that needs to be deleted.