5524e79eb9b7b7d3309a0ca0381479d22b23d008
7 #define COIN_BUTTON 7 //physically pin 7
8 #define SYNC_PIN 4 //physically pin 16
12 int one_second_ago
= 0;
13 int switch_state
; //Keeps track of what state the software thinks the switch should be in
18 pinMode(COIN_BUTTON
, INPUT
);
19 pinMode(SYNC_PIN
, INPUT
);
20 pullUpDnControl(COIN_BUTTON
, PUD_UP
);
21 pullUpDnControl(SYNC_PIN
, PUD_UP
);
26 delay(config
.sync_switch_delay
); //wait
30 int validate_switch_state()
32 if(config
.sync_switch
== 0 || digitalRead(SYNC_PIN
) == switch_state
)
35 printf("Sync pin is not what I expected, attempting to switch signal\n");
38 return digitalRead(SYNC_PIN
) == switch_state
;
43 return (unsigned)time(NULL
);
48 if(one_second_ago
!= now() && expires
!= -1)
50 printf("You have %d seconds remaining\n", expires
- now());
51 one_second_ago
= now();
54 if(expires
!= -1 && expires
<= now())
56 printf("It's all ogre now\n");
58 switch_state
= 1 - switch_state
;
67 if(digitalRead(COIN_BUTTON
) == LOW
)
69 if(config
.external_timer
!= 1)
71 printf("Nice! I just added %d to your time.\n", config
.credit_value
);
74 if(expires
== -1) //Initial credit, set the expiry to now plus time
76 expires
= now() + config
.credit_value
;
77 } else { //expiry already set, simply extend by time
78 expires
+= config
.credit_value
;
81 //wait for button to be released
82 while(digitalRead(COIN_BUTTON
) == LOW
)
84 //I don't see this happening, but in principle if the button is held down
85 //It would be possible to stop the switch happening after time runs out
86 //So we must check for that here.
95 // But only if we are in the default state (IE waiting for a credit)
96 if(config
.default_switch_state
== switch_state
)
98 printf("Changing internal switch state from %d\n", switch_state
);
99 switch_state
= 1 - switch_state
;
100 printf("Switch state is now %d\n", switch_state
);
111 init_config(&config
);
113 switch_state
= config
.default_switch_state
;
114 printf ("Short pin 7 and 9 to increment timer.\n") ;
118 if(validate_switch_state() == 0)
120 printf("Unable to switch video signal. Exiting.\n");
125 //I don't really need to call this here but I'm doing it to see output.