int main(int argc, char *argv[])
{
- int i;
+ int old_state, new_state;
struct timespec interval;
- interval.tv_sec = 2;
+ interval.tv_sec = 1;
interval.tv_nsec = 0;
// Set up gpi pointer for direct register access
// Initialize the IO pins.
INP_GPIO(SWITCH_IN);
- // Scan the arguments.
-
+ old_state = GET_GPIO(SWITCH_IN);
+
while (1)
{
- printf("%d", GET_GPIO(SWITCH_IN));
+ new_state = GET_GPIO(SWITCH_IN);
+ if (new_state != old_state)
+ {
+ //fprintf(stderr, "Changed state to %d\n", new_state);
+ if (new_state == 0)
+ {
+ system("lightcontrol -r 100 -g 100 -b 100 -w 100");
+ }
+ else
+ {
+ system("lightcontrol -r 0 -g 0 -b 0 -w 0");
+ }
+
+ old_state = new_state;
+ }
nanosleep(&interval, NULL);
}