Skip to content

Commit bc721d5

Browse files
committed
Add sure electronics led matrix example
1 parent d4f5b67 commit bc721d5

File tree

3 files changed

+395
-0
lines changed

3 files changed

+395
-0
lines changed

examples/led_matrix/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
This example depends on the ht1632c library which can be found at
2+
https://github.com/wildstray/ht1632c.
3+
4+
The patch in the folder with this example needs to be applied to the above
5+
library for it to work.

examples/led_matrix/ht1632c.patch

+241
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
1+
diff --git a/font.h b/font.h
2+
index 52cff88..37c801a 100644
3+
--- a/font.h
4+
+++ b/font.h
5+
@@ -1,6 +1,6 @@
6+
#ifdef FONT_4x6
7+
// -Misc-Fixed-Medium-R-Normal--6-60-75-75-C-40-ISO10646-1
8+
-uint8_t PROGMEM font_4x6[95][4] = {
9+
+const uint8_t PROGMEM font_4x6[95][4] = {
10+
{0x00,0x00,0x00,0x00}, //
11+
{0x00,0x3a,0x00,0x00}, // !
12+
{0x30,0x00,0x30,0x00}, // "
13+
@@ -100,7 +100,7 @@ uint8_t PROGMEM font_4x6[95][4] = {
14+
#endif
15+
#ifdef FONT_5x7
16+
// -Misc-Fixed-Medium-R-Normal--7-70-75-75-C-50-ISO10646-1
17+
-uint8_t PROGMEM font_5x7[95][5] = {
18+
+const uint8_t PROGMEM font_5x7[95][5] = {
19+
{0x00,0x00,0x00,0x00,0x00}, //
20+
{0x00,0x00,0x7a,0x00,0x00}, // !
21+
{0x00,0x70,0x00,0x70,0x00}, // "
22+
@@ -200,7 +200,7 @@ uint8_t PROGMEM font_5x7[95][5] = {
23+
#endif
24+
#ifdef FONT_5x8
25+
// -Misc-Fixed-Medium-R-Normal--8-80-75-75-C-50-ISO10646-1
26+
-uint8_t PROGMEM font_5x8[95][5] = {
27+
+const uint8_t PROGMEM font_5x8[95][5] = {
28+
{0x00,0x00,0x00,0x00,0x00}, //
29+
{0x00,0x00,0x7a,0x00,0x00}, // !
30+
{0x00,0x70,0x00,0x70,0x00}, // "
31+
@@ -299,7 +299,7 @@ uint8_t PROGMEM font_5x8[95][5] = {
32+
};
33+
#endif
34+
#ifdef FONT_5x7W
35+
-uint8_t PROGMEM font_5x7w[95][5] = {
36+
+const uint8_t PROGMEM font_5x7w[95][5] = {
37+
{0x00,0x00,0x00,0x00,0x00}, //
38+
{0x00,0x00,0xfa,0x00,0x00}, // !
39+
{0x00,0xe0,0x00,0xe0,0x00}, // "
40+
@@ -398,7 +398,7 @@ uint8_t PROGMEM font_5x7w[95][5] = {
41+
};
42+
#endif
43+
#ifdef FONT_8x8
44+
-uint8_t PROGMEM font_8x8[95][8] = {
45+
+const uint8_t PROGMEM font_8x8[95][8] = {
46+
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //
47+
{0x00,0x60,0xfa,0xfa,0x60,0x00,0x00,0x00}, // !
48+
{0x00,0xe0,0xe0,0x00,0xe0,0xe0,0x00,0x00}, // "
49+
@@ -498,7 +498,7 @@ uint8_t PROGMEM font_8x8[95][8] = {
50+
#endif
51+
#ifdef FONT_6x10
52+
// -Misc-Fixed-Medium-R-Normal--10-100-75-75-C-60-ISO10646-1
53+
-uint16_t PROGMEM font_6x10[95][6] = {
54+
+const uint16_t PROGMEM font_6x10[95][6] = {
55+
{0x0000,0x0000,0x0000,0x0000,0x0000,0x0000}, //
56+
{0x0000,0x0000,0x01f4,0x0000,0x0000,0x0000}, // !
57+
{0x0000,0x01c0,0x0000,0x01c0,0x0000,0x0000}, // "
58+
@@ -598,7 +598,7 @@ uint16_t PROGMEM font_6x10[95][6] = {
59+
#endif
60+
#ifdef FONT_6x12
61+
// -Misc-Fixed-Medium-R-SemiCondensed--12-110-75-75-C-60-ISO10646-1
62+
-uint16_t PROGMEM font_6x12[95][6] = {
63+
+const uint16_t PROGMEM font_6x12[95][6] = {
64+
{0x0000,0x0000,0x0000,0x0000,0x0000,0x0000}, //
65+
{0x0000,0x0000,0x01f4,0x0000,0x0000,0x0000}, // !
66+
{0x0000,0x0380,0x0000,0x0380,0x0000,0x0000}, // "
67+
@@ -698,7 +698,7 @@ uint16_t PROGMEM font_6x12[95][6] = {
68+
#endif
69+
#ifdef FONT_6x13
70+
// -Misc-Fixed-Medium-R-SemiCondensed--13-120-75-75-C-60-ISO10646-1
71+
-uint16_t PROGMEM font_6x13[95][6] = {
72+
+const uint16_t PROGMEM font_6x13[95][6] = {
73+
{0x0000,0x0000,0x0000,0x0000,0x0000,0x0000}, //
74+
{0x0000,0x0000,0x07f4,0x0000,0x0000,0x0000}, // !
75+
{0x0000,0x0700,0x0000,0x0700,0x0000,0x0000}, // "
76+
@@ -798,7 +798,7 @@ uint16_t PROGMEM font_6x13[95][6] = {
77+
#endif
78+
#ifdef FONT_6x13B
79+
// -Misc-Fixed-Bold-R-SemiCondensed--13-120-75-75-C-60-ISO10646-1
80+
-uint16_t PROGMEM font_6x13B[95][6] = {
81+
+const uint16_t PROGMEM font_6x13B[95][6] = {
82+
{0x0000,0x0000,0x0000,0x0000,0x0000,0x0000}, //
83+
{0x0000,0x0000,0x07f4,0x07f4,0x0000,0x0000}, // !
84+
{0x0700,0x0700,0x0000,0x0700,0x0700,0x0000}, // "
85+
@@ -898,7 +898,7 @@ uint16_t PROGMEM font_6x13B[95][6] = {
86+
#endif
87+
#ifdef FONT_6x13O
88+
// -Misc-Fixed-Medium-O-SemiCondensed--13-120-75-75-C-60-ISO10646-1
89+
-uint16_t PROGMEM font_6x13O[95][6] = {
90+
+const uint16_t PROGMEM font_6x13O[95][6] = {
91+
{0x0000,0x0000,0x0000,0x0000,0x0000,0x0000}, //
92+
{0x0000,0x0000,0x0074,0x0780,0x0000,0x0000}, // !
93+
{0x0000,0x0000,0x0100,0x0600,0x0100,0x0600}, // "
94+
@@ -998,7 +998,7 @@ uint16_t PROGMEM font_6x13O[95][6] = {
95+
#endif
96+
#ifdef FONT_6x9
97+
// -Misc-Fixed-Medium-R-Normal--9-90-75-75-C-60-ISO10646-1
98+
-uint16_t PROGMEM font_6x9[95][6] = {
99+
+const uint16_t PROGMEM font_6x9[95][6] = {
100+
{0x0000,0x0000,0x0000,0x0000,0x0000,0x0000}, //
101+
{0x0000,0x0000,0x00f4,0x0000,0x0000,0x0000}, // !
102+
{0x0000,0x00e0,0x0000,0x00e0,0x0000,0x0000}, // "
103+
@@ -1098,7 +1098,7 @@ uint16_t PROGMEM font_6x9[95][6] = {
104+
#endif
105+
#ifdef FONT_7x13
106+
// -Misc-Fixed-Medium-R-Normal--13-120-75-75-C-70-ISO10646-1
107+
-uint16_t PROGMEM font_7x13[95][7] = {
108+
+const uint16_t PROGMEM font_7x13[95][7] = {
109+
{0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000}, //
110+
{0x0000,0x0000,0x0000,0x07f4,0x0000,0x0000,0x0000}, // !
111+
{0x0000,0x0000,0x0700,0x0000,0x0700,0x0000,0x0000}, // "
112+
@@ -1198,7 +1198,7 @@ uint16_t PROGMEM font_7x13[95][7] = {
113+
#endif
114+
#ifdef FONT_7x13B
115+
// -Misc-Fixed-Bold-R-Normal--13-120-75-75-C-70-ISO10646-1
116+
-uint16_t PROGMEM font_7x13B[95][7] = {
117+
+const uint16_t PROGMEM font_7x13B[95][7] = {
118+
{0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000}, //
119+
{0x0000,0x0000,0x07ec,0x07ec,0x0000,0x0000,0x0000}, // !
120+
{0x0000,0x0700,0x0700,0x0000,0x0700,0x0700,0x0000}, // "
121+
@@ -1298,7 +1298,7 @@ uint16_t PROGMEM font_7x13B[95][7] = {
122+
#endif
123+
#ifdef FONT_7x13O
124+
// -Misc-Fixed-Medium-O-Normal--13-120-75-75-C-70-ISO10646-1
125+
-uint16_t PROGMEM font_7x13O[95][7] = {
126+
+const uint16_t PROGMEM font_7x13O[95][7] = {
127+
{0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000}, //
128+
{0x0000,0x0000,0x0074,0x0780,0x0000,0x0000,0x0000}, // !
129+
{0x0000,0x0000,0x0700,0x0000,0x0700,0x0000,0x0000}, // "
130+
@@ -1398,7 +1398,7 @@ uint16_t PROGMEM font_7x13O[95][7] = {
131+
#endif
132+
#ifdef FONT_7x14
133+
// -Misc-Fixed-Medium-R-Normal--14-130-75-75-C-70-ISO10646-1
134+
-uint16_t PROGMEM font_7x14[95][7] = {
135+
+const uint16_t PROGMEM font_7x14[95][7] = {
136+
{0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000}, //
137+
{0x0000,0x0000,0x0000,0x0fec,0x0000,0x0000,0x0000}, // !
138+
{0x0000,0x0000,0x1e00,0x0000,0x1e00,0x0000,0x0000}, // "
139+
@@ -1498,7 +1498,7 @@ uint16_t PROGMEM font_7x14[95][7] = {
140+
#endif
141+
#ifdef FONT_7x14B
142+
// -Misc-Fixed-Bold-R-Normal--14-130-75-75-C-70-ISO10646-1
143+
-uint16_t PROGMEM font_7x14B[95][7] = {
144+
+const uint16_t PROGMEM font_7x14B[95][7] = {
145+
{0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000}, //
146+
{0x0000,0x0000,0x0fec,0x0fec,0x0000,0x0000,0x0000}, // !
147+
{0x0000,0x1e00,0x1e00,0x0000,0x1e00,0x1e00,0x0000}, // "
148+
@@ -1598,7 +1598,7 @@ uint16_t PROGMEM font_7x14B[95][7] = {
149+
#endif
150+
#ifdef FONT_8x13
151+
// -Misc-Fixed-Medium-R-Normal--13-120-75-75-C-80-ISO10646-1
152+
-uint16_t PROGMEM font_8x13[95][8] = {
153+
+const uint16_t PROGMEM font_8x13[95][8] = {
154+
{0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000}, //
155+
{0x0000,0x0000,0x0000,0x07f4,0x0000,0x0000,0x0000,0x0000}, // !
156+
{0x0000,0x0000,0x0700,0x0000,0x0000,0x0700,0x0000,0x0000}, // "
157+
@@ -1698,7 +1698,7 @@ uint16_t PROGMEM font_8x13[95][8] = {
158+
#endif
159+
#ifdef FONT_8x13B
160+
// -Misc-Fixed-Bold-R-Normal--13-120-75-75-C-80-ISO10646-1
161+
-uint16_t PROGMEM font_8x13B[95][8] = {
162+
+const uint16_t PROGMEM font_8x13B[95][8] = {
163+
{0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000}, //
164+
{0x0000,0x0000,0x0000,0x0fec,0x0fec,0x0000,0x0000,0x0000}, // !
165+
{0x0000,0x0f00,0x0f00,0x0000,0x0f00,0x0f00,0x0000,0x0000}, // "
166+
@@ -1798,7 +1798,7 @@ uint16_t PROGMEM font_8x13B[95][8] = {
167+
#endif
168+
#ifdef FONT_8x13O
169+
// -Misc-Fixed-Medium-O-Normal--13-120-75-75-C-80-ISO10646-1
170+
-uint16_t PROGMEM font_8x13O[95][8] = {
171+
+const uint16_t PROGMEM font_8x13O[95][8] = {
172+
{0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000}, //
173+
{0x0000,0x0000,0x0000,0x0074,0x0780,0x0000,0x0000,0x0000}, // !
174+
{0x0000,0x0000,0x0700,0x0000,0x0000,0x0700,0x0000,0x0000}, // "
175+
@@ -1898,7 +1898,7 @@ uint16_t PROGMEM font_8x13O[95][8] = {
176+
#endif
177+
#ifdef FONT_9x15
178+
// -Misc-Fixed-Medium-R-Normal--15-140-75-75-C-90-ISO10646-1
179+
-uint16_t PROGMEM font_9x15[95][9] = {
180+
+const uint16_t PROGMEM font_9x15[95][9] = {
181+
{0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000}, //
182+
{0x0000,0x0000,0x0000,0x0000,0x3f98,0x0000,0x0000,0x0000,0x0000}, // !
183+
{0x0000,0x0000,0x0000,0x1c00,0x0000,0x0000,0x1c00,0x0000,0x0000}, // "
184+
@@ -1998,7 +1998,7 @@ uint16_t PROGMEM font_9x15[95][9] = {
185+
#endif
186+
#ifdef FONT_9x15B
187+
// -Misc-Fixed-Bold-R-Normal--15-140-75-75-C-90-ISO10646-1
188+
-uint16_t PROGMEM font_9x15b[95][9] = {
189+
+const uint16_t PROGMEM font_9x15b[95][9] = {
190+
{0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000}, //
191+
{0x0000,0x0000,0x0000,0x1fe8,0x1fe8,0x0000,0x0000,0x0000,0x0000}, // !
192+
{0x0000,0x0000,0x1c00,0x1c00,0x0000,0x1c00,0x1c00,0x0000,0x0000}, // "
193+
@@ -2098,7 +2098,7 @@ uint16_t PROGMEM font_9x15b[95][9] = {
194+
#endif
195+
#ifdef FONT_8x16
196+
// -Sony-Fixed-Medium-R-Normal--16-120-100-100-C-80-ISO8859-1
197+
-uint16_t PROGMEM font_8x16[95][8] = {
198+
+const uint16_t PROGMEM font_8x16[95][8] = {
199+
{0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000}, //
200+
{0x0000,0x0000,0x7e02,0x7fe7,0x7e02,0x0000,0x0000,0x0000}, // !
201+
{0x0000,0xc800,0xf000,0x0000,0xc800,0xf000,0x0000,0x0000}, // "
202+
@@ -2197,7 +2197,7 @@ uint16_t PROGMEM font_8x16[95][8] = {
203+
};
204+
#endif
205+
#ifdef FONT_8x16B
206+
-uint16_t PROGMEM font_8x16b[95][8] = {
207+
+const uint16_t PROGMEM font_8x16b[95][8] = {
208+
{0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000}, //
209+
{0x0000,0x0000,0x7e02,0x7fe7,0x7fe7,0x7e02,0x0000,0x0000}, // !
210+
{0x0000,0xc800,0xf800,0xf000,0x0800,0xf800,0xf000,0x0000}, // "
211+
diff --git a/ht1632c.cpp b/ht1632c.cpp
212+
index f78aa15..3097cf8 100644
213+
--- a/ht1632c.cpp
214+
+++ b/ht1632c.cpp
215+
@@ -3,7 +3,7 @@
216+
#include <string.h>
217+
#include "ht1632c.h"
218+
#include "Print.h"
219+
-#include "font_b.h"
220+
+#include "font.h"
221+
#include "font_koi8.h"
222+
223+
/* fast integer (1 uint8_t) modulus - returns n % d */
224+
diff --git a/ht1632c.h b/ht1632c.h
225+
index bd18a7b..eb024ff 100644
226+
--- a/ht1632c.h
227+
+++ b/ht1632c.h
228+
@@ -24,11 +24,11 @@
229+
230+
/* Leaflab Maple specific definitions */
231+
232+
+typedef unsigned char prog_uint8_t;
233+
+typedef unsigned int prog_uint16_t;
234+
#if defined (__ARMEL__)
235+
typedef unsigned char uint8_t;
236+
typedef unsigned int uint16_t;
237+
-typedef unsigned char prog_uint8_t;
238+
-typedef unsigned int prog_uint16_t;
239+
uint8_t inline pgm_read_byte_near(uint8_t *ptr) { return (uint8_t)*ptr; }
240+
uint16_t inline pgm_read_word_near(uint16_t *ptr) { return (uint16_t)*ptr; }
241+
#define PROGMEM __FLASH__

examples/led_matrix/led_matrix.ino

+149
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
/*
2+
* current_item.ino - Example code using the menu system library.
3+
*
4+
* This example demonstrates using the library with a Sure Electronics 32x16
5+
* LED matrix.
6+
*
7+
* Copyright (c) 2015 arduino-menusystem
8+
* Licensed under the MIT license (see LICENSE)
9+
*/
10+
11+
#include <ht1632c.h>
12+
#include <MenuSystem.h>
13+
14+
// Display constants
15+
16+
#define PIN_LED_DATA 0
17+
#define PIN_LED_WR 3
18+
#define PIN_LED_CLOCK 5
19+
#define PIN_LED_CS 4
20+
#define LED_WIDTH 32
21+
#define LED_HEIGHT 16
22+
#define FONT_WIDTH 5
23+
#define FONT_HEIGHT 7
24+
25+
// Menu variables
26+
27+
MenuSystem ms;
28+
Menu mm("");
29+
MenuItem mi_time("TIME");
30+
MenuItem mi_date("DATE");
31+
Menu mu_disp("DISP*");
32+
MenuItem mi_brightness("BRTNS");
33+
MenuItem mi_color("COLOR");
34+
35+
// Display variables
36+
37+
ht1632c ledMatrix = ht1632c(&PORTB, PIN_LED_DATA, PIN_LED_WR, PIN_LED_CLOCK, PIN_LED_CS, GEOM_32x16, 2);
38+
byte color = RED;
39+
40+
// Functions
41+
42+
void update_menu() {
43+
ledMatrix.clear();
44+
45+
int y_idnt = (LED_HEIGHT / 2) - (FONT_HEIGHT / 2);
46+
ledMatrix.setfont(FONT_5x7);
47+
48+
Menu const* menu = ms.get_current_menu();
49+
char* name = menu->get_selected()->get_name();
50+
51+
// Calculate indentation for center alignment
52+
int text_width = FONT_WIDTH * strlen(name);
53+
int pixel_spare = LED_WIDTH - text_width;
54+
int x_idnt = (int) floor(pixel_spare / 2);
55+
56+
// Display text
57+
for (int i = 0; i < strlen(name); i++) {
58+
ledMatrix.putchar((i * FONT_WIDTH) + x_idnt, y_idnt, name[i], color);
59+
}
60+
ledMatrix.sendframe();
61+
}
62+
63+
bool process_serial() {
64+
char inChar;
65+
if ((inChar = Serial.read()) > 0) {
66+
switch (inChar) {
67+
case 'w':
68+
if (ms.prev()) {
69+
Serial.println("Going to previous menu item");
70+
return true;
71+
} else {
72+
return false;
73+
}
74+
case 's':
75+
if (ms.next()) {
76+
Serial.println("Going to mext menu item");
77+
return true;
78+
} else {
79+
return false;
80+
}
81+
case 'a':
82+
if (ms.back()) {
83+
Serial.println("Going up a level");
84+
return true;
85+
} else {
86+
return false;
87+
}
88+
case 'd':
89+
Serial.println("Selecting menu item");
90+
ms.select();
91+
return true;
92+
default:
93+
return false;
94+
}
95+
}
96+
97+
return false;
98+
}
99+
100+
// Menu callback functions
101+
102+
void on_time_selected(MenuItem* p_menu_item) {
103+
Serial.println("Time selected");
104+
}
105+
106+
void on_date_selected(MenuItem* p_menu_item) {
107+
Serial.println("Date selected");
108+
}
109+
110+
void on_brightness_selected(MenuItem* p_menu_item) {
111+
Serial.println("Brightness selected");
112+
}
113+
114+
void on_color_selected(MenuItem* p_menu_item) {
115+
Serial.println("Color selected");
116+
if (color == RED) {
117+
color = GREEN;
118+
} else {
119+
color = RED;
120+
}
121+
}
122+
123+
// Standard arduino functions
124+
125+
void setup() {
126+
Serial.begin(9600);
127+
128+
// LED matrix
129+
ledMatrix.clear();
130+
131+
// Menu
132+
mm.add_item(&mi_time, &on_time_selected);
133+
mm.add_item(&mi_date, &on_date_selected);
134+
mm.add_menu(&mu_disp);
135+
mu_disp.add_item(&mi_brightness, &on_brightness_selected);
136+
mu_disp.add_item(&mi_color, &on_color_selected);
137+
ms.set_root_menu(&mm);
138+
139+
update_menu();
140+
}
141+
142+
void loop() {
143+
delay(100);
144+
145+
bool changed = process_serial();
146+
if (changed) {
147+
update_menu();
148+
}
149+
}

0 commit comments

Comments
 (0)