im now trying to run a blink sequence when the variable is set to true. heres my code:
task Start_light()
{
while(true)
{
SensorValue[dgtl1] = true;
wait1Msec(500);
SensorValue[dgtl1] = false;
wait1Msec(500);
}
}
task flash2()
{
int buttonToggleState = 0;
int buttonPressed = 0;
while(1)
{
// check for a button press only if we are not already pressed.
if(vexRT[Btn5U]==1)
{
if(!buttonPressed)
{
// change the toggle state
buttonToggleState = 1 - buttonToggleState;
// Note the button is pressed
buttonPressed = 1;
}
}
else
{
// the button is not pressed
buttonPressed = 0;
}
// Now do something with our toggle flag
if(buttonToggleState)
{
startTask(Start_light);
}
else
{
stopTask(Start_light);
SensorValue[dgtl1] = false;
}
}
}
the problem is that the blink isnt working that way. it stays solid instead of activating the blink sequence
I’m just skimming with very little time. I don’t see any delay in flash2, so you could be starving the other task.
As a separate thing, 500 ms won’t look like a typical blinking light. You’ll want to lower that amount of time. It’s not a right/wrong thing. You’ll just find it’s slow enough that it looks like someone turning on a light and turning it off as opposed to a traditional “blinking.”
I don’t have the materials with me to test right now, but I believe that because you are (re)starting the task every loop interval, it never stays active long enough to reach the turn-off portion. I would recommend creating a variable, let’s say