-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmbedded_Systems_Final.ino
More file actions
55 lines (44 loc) · 1.12 KB
/
Embedded_Systems_Final.ino
File metadata and controls
55 lines (44 loc) · 1.12 KB
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
#include "Game.h"
#include "JoyStick.h"
#include <MD_MAX72xx.h>
#include <new.h>
#define pinJoyX A13
#define pinJoyY A14
#define pinJoyS A15
#define pinRand A7
#define pinCLK A2
#define pinData A0
#define pinCS A1
JoyStick joyStick(pinJoyX, pinJoyY, pinJoyS);
MD_MAX72XX mx = MD_MAX72XX(MD_MAX72XX::PAROLA_HW, pinData, pinCLK, pinCS, 1);
Game game;
uint8_t buffer[8];
void setup() {
mx.begin();
mx.control(MD_MAX72XX::INTENSITY, MAX_INTENSITY / 8);
randomSeed(analogRead(pinRand));
game.Setup();
}
void loop() {
// Reset the game when the button is pressed.
if (joyStick.ButtonDown()) {
ResetGame();
}
// If there's input, put it into result and pass it to the game.
Point result = (Point){ 0, 0 };
if (joyStick.GetInput(&result))
game.direction = result;
if (game.Update()) {
ResetGame();
}
// Pass visuals from the game to the display
// Note: The screen is drawn right to left so this needs to be set to the last
// column and the buffer created inverted
game.GetVisuals(buffer);
mx.setBuffer(7, 8, buffer);
}
void ResetGame() {
game.~Game();
new (&game) Game();
game.Setup();
}