/* GameBone Handheld Electronic Game v2 David Johnson-Davies - www.technoblogy.com - 7th December 2020 ATtiny85 @ 1 MHz (internal oscillator; BOD disabled) CC BY 4.0 Licensed under a Creative Commons Attribution 4.0 International license: http://creativecommons.org/licenses/by/4.0/ */ #include #include const int beat = 250; const int maximum = 32; // Buttons: Blue Orange Red Green int pins[] = { 2, 0, 3, 4}; // Notes: E4 C#4 A4 E3 int notes[] = { 52, 49, 57, 40 }; int sequence[maximum]; // Simple Tones ********************************************** const uint8_t scale[] PROGMEM = {239,226,213,201,190,179,169,160,151,142,134,127}; void note (int n, int octave) { int prescaler = 8 - (octave + n/12); if (prescaler<1 || prescaler>7) prescaler = 0; DDRB = (DDRB & ~(1< 1 && n < turn) misbeep(sequence[n]); else flashbeep(sequence[n]); } for (int n=0; n<=turn; n++) { if (check() != sequence[n]) { fail_sound(); return; } } sequence[turn+1] = (sequence[turn] + random(3) + 1) % 4; turn++; delay(beat); } while (turn < maximum); success_sound(); } // Setup and loop ********************************************** void sleep(void) { sleep_enable(); sleep_cpu(); } void setup() { // Set up pin change interrupts for buttons PCMSK = 1< 10000) sleep(); } while (digitalRead(pins[game])); randomSeed(millis()); delay(250); if (game == 3) simon(); else if (game == 2) echo(); else if (game == 1) quiz(); else confusion(); } // Only reset should wake us now void loop() { sleep(); }