From b98e3b09d44a7b636e7ed1d1588910a035a6c238 Mon Sep 17 00:00:00 2001 From: LEdoian Date: Fri, 15 Apr 2016 17:39:11 +0200 Subject: [PATCH] Rework main() --- main.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/main.c b/main.c index da26074..83f03a4 100644 --- a/main.c +++ b/main.c @@ -25,11 +25,16 @@ void setup (void) { // All the blackbox code gpio_set_mode(GPIOA, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO0); } +void initial_wait (void) { + gpio_clear(GPIOC, GPIO8 | GPIO9); + while (gpio_get(GPIOA, GPIO0) == 0); + return; +} + int main (void) { setup(); - gpio_clear(GPIOC, GPIO8 | GPIO9); - while (gpio_get(GPIOA, GPIO0) == 0); + initial_wait(); // Array of what leds should be on uint16_t states[4] = {0, GPIO9, GPIO8, GPIO9 | GPIO8}; @@ -37,27 +42,25 @@ int main (void) { bool pressed = true; bool change = false; char state = 0; - int timer; + int i; while (true) { - timer = DELAY; change = false; - repeat: - if (/*Button pressed, but was not*/ gpio_get(GPIOA, GPIO0) && (pressed == false) ) { - pressed = true; - if (change == false) { - direction = (direction == FORWARD ? BACKWARD : FORWARD); // Switch direction + for (i=0 ; i 0) goto repeat; - state = (direction == FORWARD ? (state + 1)%4 : (/*state+4-1*/ state+3)%4 ); + + if (change) direction = (direction == FORWARD ? BACKWARD : FORWARD); // Switch direction + state = (direction == FORWARD ? (state + 1)%4 : (/*state+4-1*/ state+3)%4 ); // New state gpio_set(GPIOC, states[state]); gpio_clear(GPIOC, (GPIO8 | GPIO9) ^ states[state]); } return 0; } +