+ return expires == -1;
+}
+
+int read_button()
+{
+ if(digitalRead(COIN_BUTTON) == LOW)
+ {
+ printf("Nice! I just added %d to your time.\n", CREDIT_EXTENSION);
+
+ //Increment timer
+ if(expires == -1) //Initial credit, set the expiry to now plus time
+ {
+ expires = now() + CREDIT_EXTENSION;
+ } else { //expiry already set, simply extend by time
+ expires += CREDIT_EXTENSION;
+ }
+
+ //wait for button to be released
+ while(digitalRead(COIN_BUTTON) == LOW)
+ {
+ //I don't see this happening, but in principle if the button is held down
+ //It would be possible to stop the switch happening after time runs out
+ //So we must check for that here.
+ if(time_over())
+ break;
+
+ delay(10);
+ }
+
+ return 1;
+ }
+
+ return 0;
+}
+
+int main (void)
+{
+ init_gpio();
+ printf ("Short pin 7 and 9 to increment timer.\n") ;
+
+ while(1)
+ {
+ read_button();
+ //I don't really need to call this here but I'm doing it to see output.
+ time_over();
+ delay(10);