Skip to content

Instantly share code, notes, and snippets.

@carlosmn
Created October 25, 2012 13:44
Show Gist options
  • Save carlosmn/3952620 to your computer and use it in GitHub Desktop.
Save carlosmn/3952620 to your computer and use it in GitHub Desktop.
Fußgängerampel-Simulation
#define SLEEP_QUANTUM 10000
#define SLEEP(n) do { \
long time = n * 100000; /* wait() sleeps 10*n microseconds */ \
while(time > SLEEP_QUANTUM) { \
wait(SLEEP_QUANTUM); \
time -= SLEEP_QUANTUM; \
} \
wait(time); \
} while(0)
LED_OFF(LED_ROT | LED_GELB | LED_GRUEN);
//===Hier die Endlosschleife quasi das Betriebssystem=====================
while(1){
while (!(P1IN & TASTE_LINKS)) {
; // Cycles verschwenden FTW
}
// Wenn die Taste gedrueckt wird
LED_ON(LED_GELB);
SLEEP(1);
LED_OFF(LED_GELB);
LED_ON(LED_ROT);
SLEEP(2);
LED_ON(LED_GELB);
SLEEP(3);
LED_OFF(LED_ROT | LED_GELB);
LED_ON(LED_GRUEN);
SLEEP(4);
LED_OFF(LED_GRUEN);
SLEEP(5);
} // Ende der Endlosschleife
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment