Skip to content

Commit 9bd5961

Browse files
author
javastraat
committed
lolshield
changed charlieplex.cpp
1 parent 019835b commit 9bd5961

File tree

30 files changed

+9714
-0
lines changed

30 files changed

+9714
-0
lines changed

libraries/LoLShield/Charliplexing.cpp

Lines changed: 660 additions & 0 deletions
Large diffs are not rendered by default.

libraries/LoLShield/Charliplexing.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
Charliplexing.h - Library for controlling the charliplexed led board
3+
from JimmiePRodgers.com
4+
Created by Alex Wenger, December 30, 2009.
5+
Modified by Matt Mets, May 28, 2010.
6+
Released into the public domain.
7+
*/
8+
9+
#ifndef Charliplexing_h
10+
#define Charliplexing_h
11+
12+
#include <inttypes.h>
13+
14+
#define SINGLE_BUFFER 0
15+
#define DOUBLE_BUFFER 1 // comment out to save memory
16+
#define GRAYSCALE 2 // comment out to save memory
17+
18+
#define FRAMERATE 80UL // Desired number of frames per second
19+
20+
#define DISPLAY_COLS 14 // Number of columns in the display
21+
#define DISPLAY_ROWS 9 // Number of rows in the display
22+
#ifdef GRAYSCALE
23+
#define SHADES 8 // Number of distinct shades to display, including black, i.e. OFF
24+
#else
25+
#define SHADES 2
26+
#endif
27+
28+
namespace LedSign
29+
{
30+
extern void Init(uint8_t mode = SINGLE_BUFFER);
31+
extern void Set(uint8_t x, uint8_t y, uint8_t c = 1);
32+
extern void SetBrightness(uint8_t brightness);
33+
#ifdef DOUBLE_BUFFER
34+
extern void Flip(bool blocking = false);
35+
#endif
36+
extern void Clear(uint8_t c = 0);
37+
extern void Horizontal(uint8_t y, uint8_t c = 0);
38+
extern void Vertical(uint8_t x, uint8_t c = 0);
39+
};
40+
41+
#endif

libraries/LoLShield/Figure.cpp

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/*
2+
Figure drawing library
3+
4+
Copyright 2009/2010 Benjamin Sonntag <[email protected]> http://benjamin.sonntag.fr/
5+
6+
History:
7+
2010-01-01 - V0.0 Initial code at Berlin after 26C3
8+
9+
This library is free software; you can redistribute it and/or
10+
modify it under the terms of the GNU Lesser General Public
11+
License as published by the Free Software Foundation; either
12+
version 2.1 of the License, or (at your option) any later version.
13+
14+
This library is distributed in the hope that it will be useful,
15+
but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
Lesser General Public License for more details.
18+
19+
You should have received a copy of the GNU Lesser General Public License
20+
along with this program; if not, write to the Free Software
21+
Foundation, Inc., 59 Temple Place - Suite 330,
22+
Boston, MA 02111-1307, USA.
23+
*/
24+
25+
#include "Figure.h"
26+
#include "Charliplexing.h"
27+
#include <Arduino.h>
28+
#include <inttypes.h>
29+
#include <avr/pgmspace.h>
30+
31+
#define C(c,r) ((c << 4) | r)
32+
33+
PROGMEM const uint8_t figuresData[][14] = {
34+
{ C(0,0), C(1,0), C(2,0), C(0,1), C(2,1), C(0,2), C(2,2), C(0,3), C(2,3), C(0,4), C(1,4), C(2,4), 255, 255 },
35+
{ C(1,0), C(0,1), C(1,1), C(1,2), C(1,3), C(0,4), C(1,4), C(2,4), 255, 255, 255, 255, 255, 255 },
36+
{ C(0,0), C(1,0), C(2,0), C(2,1), C(1,2), C(0,3), C(0,4), C(1,4), C(2,4), 255, 255, 255, 255, 255 },
37+
{ C(0,0), C(1,0), C(2,0), C(2,1), C(0,2), C(1,2), C(2,3), C(0,4), C(1,4), C(2,4), 255, 255, 255, 255 },
38+
{ C(0,0), C(2,0), C(0,1), C(2,1), C(0,2), C(1,2), C(2,2), C(2,3), C(2,4), 255, 255, 255, 255, 255 },
39+
{ C(0,0), C(1,0), C(2,0), C(0,1), C(0,2), C(1,2), C(2,2), C(2,3), C(0,4), C(1,4), C(2,4), 255, 255, 255 },
40+
{ C(0,0), C(1,0), C(2,0), C(0,1), C(0,2), C(1,2), C(2,2), C(0,3), C(2,3), C(0,4), C(1,4), C(2,4), 255, 255 },
41+
{ C(0,0), C(1,0), C(2,0), C(2,1), C(2,2), C(1,3), C(1,4), 255, 255, 255, 255, 255, 255, 255 },
42+
{ C(0,0), C(1,0), C(2,0), C(0,1), C(2,1), C(0,2), C(1,2), C(2,2), C(0,3), C(2,3), C(0,4), C(1,4), C(2,4), 255 },
43+
{ C(0,0), C(1,0), C(2,0), C(0,1), C(2,1), C(0,2), C(1,2), C(2,2), C(2,3), C(0,4), C(1,4), 255, 255, 255 }
44+
};
45+
46+
47+
/* ----------------------------------------------------------------- */
48+
/** Draws a figure (0-9). You should call it with set=1,
49+
* wait a little them call it again with set=0
50+
* @param figure is the figure [0-9]
51+
* @param x,y coordinates,
52+
* @param set is 1 or 0 to draw or clear it
53+
*/
54+
void Figure::Draw(uint8_t figure, int x, int y, uint8_t c) {
55+
const uint8_t* character = figuresData[figure];
56+
for (;;) {
57+
uint8_t data = pgm_read_byte_near(character++);
58+
if (data == 255)
59+
break;
60+
uint8_t charCol = data >> 4, charRow = data & 15;
61+
if (
62+
charCol+x<DISPLAY_COLS &&
63+
charCol+x>=0 &&
64+
charRow+y<DISPLAY_ROWS &&
65+
charRow+y>=0
66+
) {
67+
LedSign::Set(charCol+x, charRow+y, c);
68+
}
69+
}
70+
}
71+
72+
73+
/* ----------------------------------------------------------------- */
74+
/** Draw a figure in the other direction (rotated 90°)
75+
* You should call it with set=1,
76+
* wait a little them call it again with set=0
77+
* @param figure is the figure [0-9]
78+
* @param x,y coordinates,
79+
* @param set is 1 or 0 to draw or clear it
80+
*/
81+
void Figure::Draw90(uint8_t figure, int x, int y, uint8_t c) {
82+
const uint8_t* character = figuresData[figure];
83+
for (;;) {
84+
uint8_t data = pgm_read_byte_near(character++);
85+
if (data == 255)
86+
break;
87+
uint8_t charCol = data >> 4, charRow = data & 15;
88+
if (
89+
(5-charRow)+x<DISPLAY_COLS &&
90+
(5-charRow)+x>=0 &&
91+
charCol+y<DISPLAY_ROWS &&
92+
charCol+y>=0
93+
) {
94+
LedSign::Set((5-charRow)+x, charCol+y, c);
95+
}
96+
}
97+
}
98+
99+
100+
/* ----------------------------------------------------------------- */
101+
/** Scroll a number from right to left
102+
* remove unused figures (0 at the left)
103+
* valid for up to 7 figures.
104+
* @param value is the value to draw and scroll
105+
* @param x is the coordinate where we put the top of the figure [0-13]
106+
*/
107+
void Figure::Scroll90(unsigned long value,uint8_t x) {
108+
int8_t i,j,k;
109+
uint8_t figures[10];
110+
111+
j = 0;
112+
do {
113+
figures[j++] = value%10;
114+
value/=10;
115+
} while (value);
116+
117+
for (i=9+4*j; i>=0; i--) {
118+
for (k=j; k>0; k--)
119+
Figure::Draw90(figures[k-1], x, i-4*k, SHADES-1);
120+
delay(100);
121+
for (k=j; k>0; k--)
122+
Figure::Draw90(figures[k-1], x, i-4*k, 0);
123+
}
124+
}
125+
126+

libraries/LoLShield/Figure.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
Figure drawing library
3+
4+
Copyright 2009/2010 Benjamin Sonntag <[email protected]> http://benjamin.sonntag.fr/
5+
6+
History:
7+
2010-01-01 - V0.0 Initial code at Berlin after 26C3
8+
9+
This library is free software; you can redistribute it and/or
10+
modify it under the terms of the GNU Lesser General Public
11+
License as published by the Free Software Foundation; either
12+
version 2.1 of the License, or (at your option) any later version.
13+
14+
This library is distributed in the hope that it will be useful,
15+
but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
Lesser General Public License for more details.
18+
19+
You should have received a copy of the GNU Lesser General Public License
20+
along with this program; if not, write to the Free Software
21+
Foundation, Inc., 59 Temple Place - Suite 330,
22+
Boston, MA 02111-1307, USA.
23+
*/
24+
25+
#ifndef Figures_h
26+
#define Figures_h
27+
28+
#include <inttypes.h>
29+
30+
namespace Figure
31+
{
32+
extern void Draw(uint8_t figure, int x, int y, uint8_t c=1);
33+
extern void Draw90(uint8_t figure, int x, int y, uint8_t c=1);
34+
extern void Scroll90(unsigned long value, uint8_t x=3);
35+
}
36+
37+
#endif
38+

0 commit comments

Comments
 (0)