-
Notifications
You must be signed in to change notification settings - Fork 1
/
arduino-led-matrix.ino
160 lines (141 loc) · 3.48 KB
/
arduino-led-matrix.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#include <avr/pgmspace.h>
#include "src/libraries/FastLED/FastLED.h"
#include "src/bitmaps/digdug.h"
#include "src/bitmaps/frogger.h"
#include "src/bitmaps/galaga.h"
#include "src/bitmaps/pacman.h"
#include "src/bitmaps/smb.h"
#include "src/bitmaps/qbert.h"
#define DATA_PIN 4
#define BUTTON_PIN 3
#define BUTTONTWO_PIN 2
#define NUM_LEDS 256
#define BRIGHTNESS 16
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
#define COLS 16
const int MAX_SELECTION = 4;
const int MAX_SELECTION_TWO[] = { 0, 3, 3, 4 };
CRGB leds[NUM_LEDS];
volatile int selection = 0;
volatile int selectionTwo = 0;
long lastDebounceTime = 0;
long lastDebounceTimeTwo = 0;
long debounce = 100;
void setup() {
delay(3000); // power-up safety delay
Serial.begin(9600);
FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.setBrightness(BRIGHTNESS);
FastLED.clear();
pinMode(BUTTON_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(BUTTON_PIN), buttonToggled, RISING);
pinMode(BUTTONTWO_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(BUTTONTWO_PIN), buttonTwoToggled, RISING);
selection = 1;
selectionTwo = 0;
Serial.print("Setup Complete");
}
void drawBitmap(const long* bitmap) {
FastLED.clear();
bool LTR = true;
for (int i = 0; i < NUM_LEDS; i++) {
if (LTR) {
for (int j = 0; j < COLS; j++) {
leds[i + j] = pgm_read_dword(&(bitmap[i + j]));
}
} else {
for (int j = COLS - 1; j > 0; j--) {
leds[i + COLS - j] = pgm_read_dword(&(bitmap[i + j - 1]));
}
}
i = i + COLS - 1;
LTR = !LTR;
}
FastLED.show();
}
void drawAnimation(const long* bitmaps, int s, int delayTime) {
for (int i = 0; i < s; i++) {
drawBitmap(bitmaps[i]);
delay(delayTime);
}
}
void buttonToggled() {
if (millis() - lastDebounceTime > debounce) {
selectionTwo = 0;
selection++;
if (selection > MAX_SELECTION) selection = 1;
lastDebounceTime = millis();
}
}
void buttonTwoToggled() {
if (millis() - lastDebounceTimeTwo > debounce) {
selectionTwo++;
if (selectionTwo > MAX_SELECTION_TWO[selection]) selectionTwo = 0;
lastDebounceTimeTwo = millis();
}
}
void galagaLoop() {
switch (selectionTwo) {
case 1:
drawAnimation(GalagaBoss, GalagaBossSize, 500);
break;
case 2:
drawAnimation(GalagaGoei, GalagaGoeiSize, 500);
break;
case 3:
drawAnimation(GalagaZako, GalagaZakoSize, 500);
break;
default:
drawBitmap(GalagaShip);
break;
}
}
void digDugLoop() {
switch (selectionTwo) {
case 1:
drawAnimation(DigDugTaizoShovel, DigDugTaizoShovelSize, 500);
break;
case 2:
drawAnimation(DigDugPooka, DigDugPookaSize, 500);
break;
case 3:
drawAnimation(DigDugFygar, DigDugFygarSize, 500);
break;
default:
drawBitmap(DigDugTaizoShovel01);
break;
}
}
void miscLoop() {
switch (selectionTwo) {
case 1:
drawAnimation(Frogger, FroggerSize, 500);
break;
case 2:
drawAnimation(Qbert, QbertSize, 500);
break;
case 3:
drawAnimation(PacManMsPac, PacManMsPacSize, 100);
break;
case 4:
drawAnimation(PacManBlinky, PacManBlinkySize, 500);
break;
default:
drawBitmap(SMBMario01);
break;
}
}
void loop() {
switch (selection) {
case 1:
galagaLoop();
break;
case 2:
digDugLoop();
break;
case 3:
miscLoop();
break;
}
}