Skip to content

Commit d981d42

Browse files
committed
Adding an example for VGA and Nokia screen, improving the readme, adding the ability ro draw an outline around the blocks
1 parent 912a873 commit d981d42

File tree

5 files changed

+429
-91
lines changed

5 files changed

+429
-91
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,19 @@ An Arduino library for drawing letters and numbers using a falling block style a
44

55
[![alt text](https://j.gifs.com/6RvBDl.gif "Tetris clock animation")](https://youtu.be/BGmjvfqf_0U)
66

7-
Tested using ESP8266 & ESP32 on RGB Led matrixes (using the [PxMatrix library](https://github.com/2dom/PxMatrix/)), but potentially works on any display that uses Adafruit GFX library
7+
Deisgined orginally for RGB LED Matrixes, but it should in theory work with any display that uses the Adafruit GFX library.
8+
9+
### Displays/Libraries tested ( Examples included)
10+
- RGB LED Matrix using the [PxMatrix library](https://github.com/2dom/PxMatrix/) - ESP8266 and ESP32
11+
- VGA Display using the [Bitluni ESP32Lib](https://github.com/bitluni/ESP32Lib) - ESP32
12+
- Nokia 5110 Screen using a modified [Adafruit PCD8544 library](https://github.com/bbx10/Adafruit-PCD8544-Nokia-5110-LCD-library/tree/esp8266) - ESP8266
813

914
PLEASE NOTE: There are some issues with ESP8266 sketches that make use of WiFi as well, there is an issue open for this: https://github.com/toblum/TetrisAnimation/issues/3
1015

1116
## Installation & Setup
1217

1318
Search for "Tetris Animation" on the Arduino library manager
1419

15-
If you are using an RGB LED Matrix, Install the "PXMatrix" library from the library manager. This will also require the Adafruit GFX library.
16-
1720
## Basic Usage
1821

1922
See examples for more details.
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
/*******************************************************************
2+
Example showing writing text using the TetrisAnimation
3+
library for the ESP32.
4+
* *
5+
Written by Brian Lough (witnessmenow on Github)
6+
7+
*******************************************************************/
8+
9+
// ----------------------------
10+
// Standard Libraries - Already Installed if you have ESP32 set up
11+
// ----------------------------
12+
13+
#include <Ticker.h>
14+
#include <SPI.h>
15+
16+
// ----------------------------
17+
// Additional Libraries - each one of these will need to be installed.
18+
// ----------------------------
19+
20+
#include <Adafruit_GFX.h>
21+
// Adafruit GFX library is a dependancy for the Adafruit_PCD8544 Library
22+
// Can be installed from the library manager
23+
// https://github.com/adafruit/Adafruit-GFX-Library
24+
25+
#include <Adafruit_PCD8544.h>
26+
// NOTE: This is not the one from the library manager!!!
27+
// Used for controlling the Nokia Screen
28+
// Install from Github
29+
// https://github.com/bbx10/Adafruit-PCD8544-Nokia-5110-LCD-library/tree/esp8266
30+
// Make sure its on the "esp8266" branch
31+
32+
#include <TetrisMatrixDraw.h>
33+
// This library!
34+
// https://github.com/toblum/TetrisAnimation
35+
36+
37+
Ticker animationTicker;
38+
39+
// ESP8266 Software SPI (slower updates, more flexible pin options):
40+
// pin 14 - Serial clock out (SCLK)
41+
// pin 13 - Serial data out (DIN)
42+
// pin 12 - Data/Command select (D/C)
43+
// pin 5 - LCD chip select (CS)
44+
// pin 4 - LCD reset (RST)
45+
//Adafruit_PCD8544 display = Adafruit_PCD8544(14, 13, 12, 5, 4);
46+
47+
// If using an ESP8266, use this option. Comment out the other options.
48+
// ESP8266 Hardware SPI (faster, but must use certain hardware pins):
49+
// SCK is LCD serial clock (SCLK) - this is pin 14 on Huzzah ESP8266
50+
// MOSI is LCD DIN - this is pin 13 on an Huzzah ESP8266
51+
// pin 12 - Data/Command select (D/C) on an Huzzah ESP8266
52+
// pin 5 - LCD chip select (CS)
53+
// pin 4 - LCD reset (RST)
54+
Adafruit_PCD8544 display = Adafruit_PCD8544(12, 5, 4);
55+
56+
// On my D1 Mini I have the following wired up:
57+
// Screen to D1 Mini
58+
// GND -> GND
59+
// LIGHT -> D3
60+
// VCC -> 3V
61+
// CLK -> D5
62+
// DIN -> D7
63+
// DC -> D6
64+
// CE -> D8
65+
// RST -> D0
66+
67+
TetrisMatrixDraw tetris(display);
68+
69+
bool showColon = true;
70+
71+
boolean animate = true;
72+
73+
void animationHandler()
74+
{
75+
if (true) {
76+
display.clearDisplay();
77+
animate = !tetris.drawText(10, 30);
78+
display.display();
79+
}
80+
}
81+
82+
83+
void drawIntro(int x = 0, int y = 0)
84+
{
85+
tetris.drawChar("T", x, y, tetris.tetrisBLACK);
86+
tetris.drawChar("e", x + 5, y, tetris.tetrisMAGENTA);
87+
tetris.drawChar("t", x + 11, y, tetris.tetrisYELLOW);
88+
tetris.drawChar("r", x + 17, y, tetris.tetrisGREEN);
89+
tetris.drawChar("i", x + 22, y, tetris.tetrisBLUE);
90+
tetris.drawChar("s", x + 27, y, tetris.tetrisRED);
91+
92+
tetris.drawChar("L", x - 2, y + 9, tetris.tetrisRED);
93+
tetris.drawChar("e", x + 5, y + 9, tetris.tetrisMAGENTA);
94+
tetris.drawChar("t", x + 11, y + 9, tetris.tetrisYELLOW);
95+
tetris.drawChar("t", x + 17, y + 9, tetris.tetrisGREEN);
96+
tetris.drawChar("e", x + 23, y + 9, tetris.tetrisBLUE);
97+
tetris.drawChar("r", x + 29, y + 9, tetris.tetrisRED);
98+
tetris.drawChar("s", x + 37, y + 9, tetris.tetrisMAGENTA);
99+
}
100+
101+
void setup() {
102+
Serial.begin(115200);
103+
display.begin();
104+
// init done
105+
106+
// you can change the contrast around to adapt the display
107+
// for the best viewing!
108+
display.setContrast(60);
109+
110+
// My "LIGHT" pin is wired to D3
111+
// This turns the backlight on
112+
pinMode(D3, OUTPUT);
113+
digitalWrite(D3, LOW);
114+
115+
yield();
116+
117+
drawIntro(10, 10);
118+
119+
delay(2000);
120+
121+
// Scale causing a crash for me, no idea why?
122+
// tetris.scale = 2;
123+
124+
// Must use upercase characters
125+
// See below for all supported chars
126+
127+
tetris.setText("HELLO!");
128+
129+
animationTicker.attach(0.05, animationHandler);
130+
131+
132+
delay(10000);
133+
animate = true;
134+
tetris.setText("!#$%&'()");
135+
136+
delay(10000);
137+
animate = true;
138+
tetris.setText("*+,-./");
139+
140+
delay(10000);
141+
animate = true;
142+
tetris.setText("01234567");
143+
144+
delay(10000);
145+
animate = true;
146+
tetris.setText("89:;<=>?");
147+
148+
delay(10000);
149+
animate = true;
150+
tetris.setText("@ABCDEFG");
151+
152+
delay(10000);
153+
animate = true;
154+
tetris.setText("HIJKLMNO");
155+
156+
delay(10000);
157+
animate = true;
158+
tetris.setText("PQRSTUVW");
159+
160+
delay(10000);
161+
animate = true;
162+
tetris.setText("XYZ");
163+
164+
165+
}
166+
167+
168+
void loop() {
169+
}
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
/*******************************************************************
2+
Example showing writing text using the TetrisAnimation
3+
library on a VGA Screen using Bitluni's ESP32Lib for the ESP32.
4+
*
5+
For Use with products from Bitluni's Tindie:
6+
https://www.tindie.com/stores/bitluni/
7+
*
8+
Written by Brian Lough (witnessmenow on Github)
9+
10+
*******************************************************************/
11+
12+
// ----------------------------
13+
// Standard Libraries - Already Installed if you have ESP32 set up
14+
// ----------------------------
15+
16+
// ----------------------------
17+
// Additional Libraries - each one of these will need to be installed.
18+
// ----------------------------
19+
20+
// The 3 includes below all belong to Bitluni ESP32Lib
21+
// They are being used to interface with the VGA
22+
// Can be installed from the library manager (Search for Bitluni)
23+
// https://github.com/adafruit/Adafruit-GFX-Library
24+
#include <ESP32Lib.h>
25+
#include <Ressources/Font6x8.h>
26+
#include <GfxWrapper.h>
27+
28+
// Adafruit GFX library is a dependancy for the GfxWrapper
29+
// Can be installed from the library manager
30+
// https://github.com/adafruit/Adafruit-GFX-Library
31+
32+
#include <TetrisMatrixDraw.h>
33+
// This library!
34+
// https://github.com/toblum/TetrisAnimation
35+
36+
37+
portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;
38+
39+
hw_timer_t * animationTimer = NULL;
40+
41+
//VGA Device
42+
VGA6Bit vga;
43+
GfxWrapper<VGA6Bit> gfx(vga, 320, 200);
44+
45+
TetrisMatrixDraw tetris(gfx);
46+
47+
bool showColon = true;
48+
49+
#define ANIMATION_TIME 50000 // Controls the speed in which the blocks update,
50+
// increase this number to make it slower
51+
52+
boolean animate = true;
53+
54+
void animationHandler()
55+
{
56+
portENTER_CRITICAL_ISR(&timerMux);
57+
if(animate){
58+
vga.clear(0);
59+
animate = !tetris.drawText(25, 150);
60+
vga.show();
61+
}
62+
portEXIT_CRITICAL_ISR(&timerMux);
63+
}
64+
65+
66+
void drawIntro(int x = 0, int y = 0)
67+
{
68+
tetris.drawChar("T", x, y, tetris.tetrisCYAN);
69+
tetris.drawChar("e", x + 5, y, tetris.tetrisMAGENTA);
70+
tetris.drawChar("t", x + 11, y, tetris.tetrisYELLOW);
71+
tetris.drawChar("r", x + 17, y, tetris.tetrisGREEN);
72+
tetris.drawChar("i", x + 22, y, tetris.tetrisBLUE);
73+
tetris.drawChar("s", x + 27, y, tetris.tetrisRED);
74+
75+
tetris.drawChar("L", x - 2, y + 9, tetris.tetrisRED);
76+
tetris.drawChar("e", x + 5, y + 9, tetris.tetrisMAGENTA);
77+
tetris.drawChar("t", x + 11, y + 9, tetris.tetrisYELLOW);
78+
tetris.drawChar("t", x + 17, y + 9, tetris.tetrisGREEN);
79+
tetris.drawChar("e", x + 23, y + 9, tetris.tetrisBLUE);
80+
tetris.drawChar("r", x + 29, y + 9, tetris.tetrisRED);
81+
tetris.drawChar("s", x + 37, y + 9, tetris.tetrisMAGENTA);
82+
}
83+
84+
void setup() {
85+
Serial.begin(115200);
86+
vga.setFrameBufferCount(2);
87+
88+
// You may need to change which board you are using:
89+
// https://github.com/bitluni/ESP32Lib#predefined-pin-configurations
90+
vga.init(vga.MODE320x200, vga.VGAv01);
91+
92+
yield();
93+
94+
drawIntro(10, 10); //This is tiny at this resolution!!!
95+
96+
delay(2000);
97+
98+
// Scaling each block that makes up to be 6 pixels wide
99+
tetris.scale = 6;
100+
101+
// Drawing an outline around each block to give them defintion
102+
tetris.outLineColour = 0x0000; // any RGB 565 colour, defaults to black anyways
103+
tetris.drawOutline = true;
104+
105+
// Must use upercase characters
106+
// See below for all supported chars
107+
tetris.setText("HELLO!");
108+
109+
animationTimer = timerBegin(1, 80, true);
110+
timerAttachInterrupt(animationTimer, &animationHandler, true);
111+
timerAlarmWrite(animationTimer, ANIMATION_TIME, true);
112+
timerAlarmEnable(animationTimer);
113+
114+
115+
delay(10000);
116+
animate = true;
117+
tetris.setText("!#$%&'()");
118+
119+
delay(10000);
120+
animate = true;
121+
tetris.setText("*+,-./");
122+
123+
delay(10000);
124+
animate = true;
125+
tetris.setText("01234567");
126+
127+
delay(10000);
128+
animate = true;
129+
tetris.setText("89:;<=>?");
130+
131+
delay(10000);
132+
animate = true;
133+
tetris.setText("@ABCDEFG");
134+
135+
delay(10000);
136+
animate = true;
137+
tetris.setText("HIJKLMNO");
138+
139+
delay(10000);
140+
animate = true;
141+
tetris.setText("PQRSTUVW");
142+
143+
delay(10000);
144+
animate = true;
145+
tetris.setText("XYZ");
146+
147+
148+
}
149+
150+
151+
void loop() {
152+
}

0 commit comments

Comments
 (0)