-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathKeebcard.ino
129 lines (108 loc) · 2.85 KB
/
Keebcard.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include <TinyWireM.h>
#include <Tiny4kOLED.h>
// #include <Entropy.h>
#include "settings.h"
// PROGRAM DEFINES =============================================================
// uncomment whichever one you want
// #define BUSINESS_CARD
#define TETRIS
// #define CONWAY
// #define PONG
// #define SNAKE
// cut down on features since digispark has a big bootloader
// #define DIGISPARK
#ifdef TETRIS
#include "Tetris.h"
#elif defined(CONWAY)
#include "Conway.h"
#elif defined(PONG)
#include "Pong.h"
#elif defined(BUSINESS_CARD)
#include "BusinessCard.h"
#elif defined(SNAKE)
#include "Snake.h"
#endif
void universal_setup() {
// flip screen horizontally
// oled.setSegmentRemap(0xA0);
// flip screen vertically
// oled.setComOutputDirection(0xC0);
oled.begin();
oled.setFont(FONT8X16);
// Switch the half of RAM that we are writing to, to be the half that is non currently displayed
oled.switchRenderFrame();
// clear both buffers of any dead squirrels
oled.clear();
oled.switchFrame();
oled.clear();
// Turn on the display
oled.on();
// seed random number with value from the analog pin
// it doesn't vary all that much, but it helps
// srand(analogRead(MIDDLE_BUTTON) + analogRead(2) + analogRead(3));
// here's the good stuff, Entropy based off clock jitter
// Entropy.initialize();
pinMode(LEFT_BUTTON, INPUT);
pinMode(RIGHT_BUTTON, INPUT);
pinMode(MIDDLE_BUTTON, INPUT);
#ifdef SNAKE
oled.setMemoryAddressingMode(0); // TODO prolly don't need this
// no double buffering for now. very little to update so it runs fast anyways
oled.switchRenderFrame();
#endif
}
void setup() {
universal_setup();
setup_game();
}
void setup_game() {
#ifdef TETRIS
GIMSK = 0b00100000; // turns on pin change interrupts
PCMSK = 0b00011010; // turn on interrupts on pins PB0, PB1, &amp; PB4
sei(); // enables interrupts
Tetris tetris(&oled);
gameOver(tetris.run());
oled.switchFrame();
#elif defined(CONWAY)
oled.setMemoryAddressingMode(0); // TODO prolly don't need this
Conway conway(&oled);
conway.run();
#elif defined(BUSINESS_CARD)
businessCard(&oled);
#elif defined(PONG)
oled.setCursor(8, 1);
oled.print(F("PLAYER 1 START"));
oled.switchFrame();
delay(800);
oled.switchFrame();
oled.clear();
oled.setMemoryAddressingMode(1);
Pong pong(&oled);
pong.run();
#elif defined(SNAKE)
oled.setCursor(8, 1);
oled.print(F("NOKIA OS"));
// oled.switchFrame();
delay(800);
// oled.switchFrame();
oled.clear();
Snake snake(&oled);
gameOver(snake.run());
#endif
}
void loop() {
if (digitalRead(MIDDLE_BUTTON) == LOW) {
// oled.clear();
// oled.switchFrame();
// oled.clear();
// setup_game();
}
}
void gameOver(uint32_t score) {
oled.clear();
oled.setCursor(0, 0);
oled.print(F("Game Over!"));
oled.setCursor(0, 2);
oled.print(F("Score: "));
oled.print(score);
}