10 static const uint16_t GRID_X = 60, GRID_Y = 80, PIXEL_SCALE = 4, PATTERN_COUNT = 5;
11 unsigned long wait, next;
13 uint8_t worldX, worldY;
15 unsigned char frontGrid[(uint16_t)(((
float)GRID_X / 8.0) + 1.0)][GRID_Y];
16 unsigned char backGrid[(uint16_t)(((
float)GRID_X / 8.0) + 1.0)][GRID_Y];
17 unsigned char patterns[PATTERN_COUNT][8] = {
19 {B00000000, B00000000, B00010000, B00010000, B00010000, B00000000, B00000000, B00000000},
21 {B00000000, B00000000, B00010000, B00001000, B00111000, B00000000, B00000000, B00000000},
23 {B00000000, B00000000, B00111100, B01000100, B00000100, B01001000, B00000000, B00000000},
25 {B00000000, B00000000, B01111100, B10000100, B00000100, B10001000, B00100000, B00000000},
27 {B00000000, B00000000, B01111110, B10000010, B00000010, B10000100, B00110000, B00000000}};
29 void setFGBit(uint16_t x, uint16_t y, uint8_t val)
31 uint16_t subX = (float)x / 8.0;
34 frontGrid[subX][y] = frontGrid[subX][y] | (1 << (x % 8));
38 frontGrid[subX][y] = frontGrid[subX][y] & ~(1 << (x % 8));
41 unsigned char getFGBit(uint16_t x, uint16_t y)
43 return frontGrid[(uint16_t)((
float)x / 8.0)][y] & (1 << (x % 8));
45 void setBGBit(uint16_t x, uint16_t y, uint16_t val)
47 uint16_t subX = (float)x / 8.0;
50 backGrid[subX][y] = backGrid[subX][y] | (1 << (x % 8));
54 backGrid[subX][y] = backGrid[subX][y] & ~(1 << (x % 8));
57 unsigned char getBGBit(uint16_t x, uint16_t y)
59 return backGrid[(uint16_t)((
float)x / 8.0)][y] & (1 << (x % 8));
61 unsigned char getPattBit(uint16_t pattern, uint16_t x, uint16_t y)
63 return patterns[pattern][y] & (1 << (x % 8));
66 bool cgolGetDot(uint16_t x, uint16_t y)
69 int16_t xleft = x - 1, xright = x + 1, ytop = y + 1, ybottom = y - 1;
78 if (getFGBit(xleft, ytop))
80 if (getFGBit(x, ytop))
82 if (getFGBit(xright, ytop))
84 if (getFGBit(xleft, y))
86 if (getFGBit(xright, y))
88 if (getFGBit(xleft, ybottom))
90 if (getFGBit(x, ybottom))
92 if (getFGBit(xright, ybottom))
94 if (getFGBit(x, y) && count < 2)
98 else if (getFGBit(x, y) && (count == 2 || count == 3))
102 else if (getFGBit(x, y) && count > 3)
106 else if (getFGBit(x, y) ==
false && count == 3)
115 for (uint16_t x = 0; x < GRID_X; x++)
117 for (uint16_t y = 0; y < GRID_Y; y++)
119 setBGBit(x, y, cgolGetDot(x, y));
140 for (uint16_t x = 0; x < GRID_X; x++)
142 for (uint16_t y = 0; y < GRID_Y; y++)
144 bool bit = getBGBit(x, y);
146 m_badge->
display().fillRect(x * PIXEL_SCALE, y * PIXEL_SCALE, PIXEL_SCALE, PIXEL_SCALE,
147 bit ? ILI9341_WHITE : ILI9341_BLACK);
200 for (
int x = 0; x < GRID_X; x++)
202 for (
int y = 0; y < GRID_Y; y++)
204 bool bit = random(2);
206 m_badge->
display().fillRect(x * PIXEL_SCALE, y * PIXEL_SCALE, PIXEL_SCALE, PIXEL_SCALE,
207 bit ? ILI9341_WHITE : ILI9341_BLACK);
220 if (button->isActive())
222 if (button->getID() == 1)
224 for (
int x = 0; x < GRID_X; x++)
226 for (
int y = 0; y < GRID_Y; y++)
233 currPattern = currPattern >= PATTERN_COUNT ? PATTERN_COUNT - 1 : currPattern;
234 uint16_t xOffset = (GRID_X / 2) - 4, yOffset = (GRID_Y / 2) - 4;
235 for (
int x = 0; x < 8; x++)
237 for (
int y = 0; y < 8; y++)
239 bool bit = getPattBit(currPattern, 7 - x, y);
240 setFGBit(x + xOffset, y + yOffset, bit);
241 m_badge->
display().fillRect((x + xOffset) * PIXEL_SCALE, (y + yOffset) * PIXEL_SCALE,
242 PIXEL_SCALE, PIXEL_SCALE,
243 bit ? ILI9341_WHITE : ILI9341_BLACK);
247 if (button->getID() == 2)
249 for (
int x = 0; x < GRID_X; x++)
251 for (
int y = 0; y < GRID_Y; y++)
258 currPattern = currPattern < 0 ? 0 : currPattern;
259 uint16_t xOffset = (GRID_X / 2) - 4, yOffset = (GRID_Y / 2) - 4;
260 for (
int x = 0; x < 8; x++)
262 for (
int y = 0; y < 8; y++)
264 bool bit = getPattBit(currPattern, 7 - x, y);
265 setFGBit(x + xOffset, y + yOffset, bit);
266 m_badge->
display().fillRect((x + xOffset) * PIXEL_SCALE, (y + yOffset) * PIXEL_SCALE,
267 PIXEL_SCALE, PIXEL_SCALE,
268 bit ? ILI9341_WHITE : ILI9341_BLACK);
272 if (button->getID() == 0)
275 wait = wait > 10000 ? 10000 : wait;
277 if (button->getID() == 3)
280 wait = wait < 100 ? 100 : wait;
282 if (button->getID() == 4)
285 for (
int x = 0; x < GRID_X; x++)
287 for (
int y = 0; y < GRID_Y; y++)
289 bool bit = random(2);
291 m_badge->
display().fillRect(x * PIXEL_SCALE, y * PIXEL_SCALE, PIXEL_SCALE, PIXEL_SCALE,
292 bit ? ILI9341_WHITE : ILI9341_BLACK);
296 if (button->getID() == 5)
315 next = millis() + wait;
Adafruit_ILI9341 & display()
Gets the TFT display driver.
Definition: Dilbert.h:44
AppManager * m_manager
Pointer to application manager.
Definition: App.h:130
virtual void onEntry()
Called when the application is entered.
Definition: App.h:70
void onEntry()
Definition: Conways.h:191
virtual bool handleButton(IButton *button)
Handle button presses.
Definition: App.h:121
App(char *name)
Creates a new instance of a badge application.
Definition: App.h:22
bool handleButton(IButton *button)
Definition: Conways.h:215
void run()
Definition: Conways.h:308
Dilbert * m_badge
Pointer to badge driver.
Definition: App.h:129
Used to encapsulate an individual application.
Definition: App.h:15
void feedBacklight(uint8_t status=BACKLIGHT_STATE_FULL)
Ensures that the backlight stays on, otherwise it is susceptible to the timeouts set in SystemConfigD...
Definition: AppManager.cpp:152