Sleep Timer Code

In a portion of our code we needed to look for a button press to change a variable. To do this we used a while loop that incremented a counter when the button was not pressed and changed the value when the button was pressed. This allowed for the user to edit the value for a set amount of time and then move on to the next portion of the code. Below is the code

 

counter = 0;
LCDWriteString(“SET MINUTES”);
LCDWriteIntXY(1, 2, minutes, 2);

//Get minutes
while(counter < 10)
{
_delay_ms(500);
LCDClear();

int temp = PIND & 0x01;
if (temp == 0x00)
{
counter += 1;
}
else
{
minutes += 1;
if (minutes > 59)
{
minutes = 0;
}
}

LCDWriteString(“SET MINUTES”);
LCDWriteIntXY(1, 2, minutes, 2);

}