I'm programming a C6 in Arduino mode with pioarduino. My code has a boolean value that has to swap back-n-forth to properly operate an electrical motor (one time in one direction, one time in the other, etc.) Yet, from time to time, I need to soft reboot my device and when doing so, it will always reset to the default value of the variable (true) rather than the "right" value.
So I thought about tagging my value with RTC_NOINIT_ATTR:
Code: Untitled.cpp Select all
RTC_NOINIT_ATTR boolean engineBalanceDirection = true;
Code: Untitled.cpp Select all
void wallclock_force_forward()
{
if (engineBalanceDirection)
{
digitalWrite(ENGINE_BALANCE_1, HIGH); // activate A+ on L293D
digitalWrite(ENGINE_BALANCE_2, LOW); // de-activate A- on L293D
}
else
{
digitalWrite(ENGINE_BALANCE_1, LOW); // de-activate A+ on L293D
digitalWrite(ENGINE_BALANCE_2, HIGH); // activate A- on L293D
}
engineBalanceDirection = !engineBalanceDirection;
delay(IMPULSE_DURATION_MS); // wait 1/2 second
// stop it all - de-activate A+ and A- on L293D
digitalWrite(ENGINE_BALANCE_1, LOW);
digitalWrite(ENGINE_BALANCE_2, LOW);
}Now, when I do this... nothing happens! Which is very odd. As if my variable could possibly be read, but any write doesn't go back to memory or is not read back as modified. Is that even possible? What am I doing wrong? Ideas are welcomed!