I am trying to understand structures.
The attached sketch flashes a LED on pin 13.
I initially thought line 51 should have been:
boolean CheckTime(makeTimer *thisTimer)
Why does this not work?
This makes it work:
boolean CheckTime(struct timer *thisTimer) //<<<<<<<<<<<<<<< LINE 51 >>>>>>>>>>>>
//Blink without Delay skeleton (using structures)
//LarryD
typedef struct timer
{
unsigned long lastMillis;
unsigned long waitMillis;
boolean restart;
boolean enableFlag;
}makeTimer;
makeTimer pin13 =
{
0, 200, true, true
};
//**********************************************************************
void setup()
{
pinMode(13, OUTPUT);
} // >>>>>>>>>>>>>> E N D O F s e t u p ( ) <<<<<<<<<<<<<<<<<
void loop()
{
//***************************
//toggle pin 13 200ms
if (CheckTime(&pin13))
{
//toggle pin 13
digitalWrite(13,!digitalRead(13));
//if you only want this section of code to happen once
//uncomment the next line
//pin13.enableFlag = false;
}
} // >>>>>>>>>>>>>> E N D O F l o o p ( ) <<<<<<<<<<<<<<<<<
//======================================================================
// F U N C T I O N S
//======================================================================
//**********************************************************************
//Delay time expired function
//lastMillis = time we started
//waitMillis = delay in mS
//restart = do we start again
//enableFlag = is this timer enabled
boolean CheckTime(struct timer *thisTimer) //<<<<<<<<<<<<<<< LINE 51 >>>>>>>>>>>>
{
//is the time up for this task?
if (thisTimer->enableFlag && millis() - thisTimer->lastMillis >= thisTimer->waitMillis)
{
//should this start again?
if(thisTimer->restart)
{
//get ready for the next iteration
thisTimer->lastMillis += thisTimer->waitMillis; //get ready for the next iteration
}
return true;
}
return false;
} // END of CheckTime()
//**********************************************************************
//======================================================================
// E N D O F C O D E
//======================================================================