diff --git a/code/code.ino b/code/code.ino index 1178d19..2eaef84 100644 --- a/code/code.ino +++ b/code/code.ino @@ -8,25 +8,58 @@ #include "uniform_int_dist.h" -#define PIN1 1 +#define BUTTON_PIN 1 +#define DISPLAY_ENABLE 3 lcg_rng rng; std::uniform_int_distribution distribution(1,16); SegmentDisplay<4, 2, 0> display; +#define NUM_SLOWDOWN 12 +const uint16_t PROGMEM SLOWDOWN[NUM_SLOWDOWN] = { + 35, 32, + 20, 64, + 8, 125, + 4, 250, + 2, 500, + 2, 1000 +}; + void setup() { - pinMode(PIN1, INPUT_PULLUP); - pinMode(3, OUTPUT); - digitalWrite(3, 0); - digitalWrite(0, 0); + pinMode(BUTTON_PIN, INPUT_PULLUP); + + pinMode(DISPLAY_ENABLE, OUTPUT); + digitalWrite(DISPLAY_ENABLE, 0); + + display.setDash(); + display.write(); } void loop() { - if(!digitalRead(PIN1)) { - display.set(distribution(rng)); - display.write(); + if(digitalRead(PIN1)) { + rng(); + return; + } + + uint8_t num; + + for(size_t i = 0; i < NUM_SLOWDOWN; i += 2) { + for(size_t j = 0; j < pgm_read_word_near(SLOWDOWN + i); ++j) { + num = distribution(rng); + display.set(num); + display.write(); + delay(pgm_read_word_near(SLOWDOWN + i + 1)); + } + } + + for(uint8_t i = 0; i < 2; ++i) { + display.setOff(); + display.write(); + delay(250); + display.set(num); + display.write(); + delay(250); } - delay(16); } diff --git a/code/segment.h b/code/segment.h index 7114b72..0cd1ec4 100644 --- a/code/segment.h +++ b/code/segment.h @@ -36,6 +36,11 @@ public: number[1] = 0xFF; } + void setDash() { + number[0] = pgm_read_byte_near(DECODER + 11); + number[1] = pgm_read_byte_near(DECODER + 11); + } + void write() { shiftOut(PIN_SER, PIN_SCLK, LSBFIRST, number[0]); shiftOut(PIN_SER, PIN_SCLK, LSBFIRST, number[1]);