Skip to content

Instantly share code, notes, and snippets.

@jsleeio
Created June 15, 2014 11:48
Show Gist options
  • Save jsleeio/b70b4dc123fba2ea76aa to your computer and use it in GitHub Desktop.
Save jsleeio/b70b4dc123fba2ea76aa to your computer and use it in GitHub Desktop.
#define LED 13
#define NDIVIDERS sizeof(divider_outputs)
uint8_t divider_outputs[] = {
12, 11, 10, 9,
8, 7, 6, 5
};
void setup(void) {
for (uint8_t i = 0; i < NDIVIDERS; i++) {
pinMode(divider_outputs[i], OUTPUT);
digitalWrite(divider_outputs[i], LOW);
}
pinMode(LED, OUTPUT);
digitalWrite(LED, LOW);
attachInterrupt(0, clock_rising, RISING);
}
uint8_t do_clock = 0;
uint16_t ticks = 0;
uint16_t led_off_at = 0;
uint16_t last_clock_at = 0;
uint16_t interval = 0;
void loop(void) {
if (do_clock) {
ticks++;
digitalWrite(LED, HIGH);
for (uint8_t i = 0; i < NDIVIDERS; i++)
digitalWrite(divider_outputs[i], ( ticks % (i + 1) ) == 0);
while(millis() < led_off_at)
;
digitalWrite(LED, LOW);
do_clock = 0;
}
}
void clock_rising(void) {
uint16_t last = millis();
do_clock = 1;
led_off_at = last + 50;
interval = last - last_clock_at;
last_clock_at = last;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment