int read_button()
{
- if(digitalRead(COIN_BUTTON) == LOW)
+ // In the case of an external timer all we need to do is set the internal switch
+ // state to match the state of the external timer pin. Low means a they can see
+ // the second input, high means show the default video.
+ if(config.external_timer == 1)
{
- // Don't do anything until button is released
- while(digitalRead(COIN_BUTTON) == LOW)
+ if(digitalRead(COIN_BUTTON) == HIGH)
{
- //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.
- time_over();
- delay(10);
+ switch_state = config.default_switch_state;
+ } else {
+ switch_state = 1 - config.default_switch_state;
}
- // Flip internal switch state, but only if we are in the default state
- // i.e., waiting for a credit
- if(config.default_switch_state == switch_state)
+ return 1;
+ } else {
+ if(digitalRead(COIN_BUTTON) == LOW)
{
- printf("Changing internal switch state from %d\n", switch_state);
- switch_state = 1 - switch_state;
- printf("Switch state is now %d\n", switch_state);
+ // Don't do anything until button is 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.
+ time_over();
+ delay(10);
+ }
- if(config.sync_switch == 0) //naively pulse the switch
- pulse_switch();
- }
+ // Flip internal switch state, but only if we are in the default state
+ // i.e., waiting for a credit
+ if(config.default_switch_state == switch_state)
+ {
+ printf("Changing internal switch state from %d\n", switch_state);
+ switch_state = 1 - switch_state;
+ printf("Switch state is now %d\n", switch_state);
+
+ if(config.sync_switch == 0) //naively pulse the switch
+ pulse_switch();
+ }
- if(config.external_timer != 1)
- {
printf("Nice! I just added %d to your time.\n", config.credit_value);
//Increment timer
expires += config.credit_value;
}
- //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 1;
}
return 0;