Skip to content

Commit

Permalink
Adding an example for VGA and Nokia screen, improving the readme, add…
Browse files Browse the repository at this point in the history
…ing the ability ro draw an outline around the blocks
  • Loading branch information
witnessmenow committed Jun 3, 2019
1 parent 912a873 commit d981d42
Show file tree
Hide file tree
Showing 5 changed files with 429 additions and 91 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ An Arduino library for drawing letters and numbers using a falling block style a

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

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
Deisgined orginally for RGB LED Matrixes, but it should in theory work with any display that uses the Adafruit GFX library.

### Displays/Libraries tested ( Examples included)
- RGB LED Matrix using the [PxMatrix library](https://github.com/2dom/PxMatrix/) - ESP8266 and ESP32
- VGA Display using the [Bitluni ESP32Lib](https://github.com/bitluni/ESP32Lib) - ESP32
- Nokia 5110 Screen using a modified [Adafruit PCD8544 library](https://github.com/bbx10/Adafruit-PCD8544-Nokia-5110-LCD-library/tree/esp8266) - ESP8266

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

## Installation & Setup

Search for "Tetris Animation" on the Arduino library manager

If you are using an RGB LED Matrix, Install the "PXMatrix" library from the library manager. This will also require the Adafruit GFX library.

## Basic Usage

See examples for more details.
Expand Down
169 changes: 169 additions & 0 deletions examples/Adafruit_PCD8544/ESP8266/AlphaTestNokia/AlphaTestNokia
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
/*******************************************************************
Example showing writing text using the TetrisAnimation
library for the ESP32.
* *
Written by Brian Lough (witnessmenow on Github)

*******************************************************************/

// ----------------------------
// Standard Libraries - Already Installed if you have ESP32 set up
// ----------------------------

#include <Ticker.h>
#include <SPI.h>

// ----------------------------
// Additional Libraries - each one of these will need to be installed.
// ----------------------------

#include <Adafruit_GFX.h>
// Adafruit GFX library is a dependancy for the Adafruit_PCD8544 Library
// Can be installed from the library manager
// https://github.com/adafruit/Adafruit-GFX-Library

#include <Adafruit_PCD8544.h>
// NOTE: This is not the one from the library manager!!!
// Used for controlling the Nokia Screen
// Install from Github
// https://github.com/bbx10/Adafruit-PCD8544-Nokia-5110-LCD-library/tree/esp8266
// Make sure its on the "esp8266" branch

#include <TetrisMatrixDraw.h>
// This library!
// https://github.com/toblum/TetrisAnimation


Ticker animationTicker;

// ESP8266 Software SPI (slower updates, more flexible pin options):
// pin 14 - Serial clock out (SCLK)
// pin 13 - Serial data out (DIN)
// pin 12 - Data/Command select (D/C)
// pin 5 - LCD chip select (CS)
// pin 4 - LCD reset (RST)
//Adafruit_PCD8544 display = Adafruit_PCD8544(14, 13, 12, 5, 4);

// If using an ESP8266, use this option. Comment out the other options.
// ESP8266 Hardware SPI (faster, but must use certain hardware pins):
// SCK is LCD serial clock (SCLK) - this is pin 14 on Huzzah ESP8266
// MOSI is LCD DIN - this is pin 13 on an Huzzah ESP8266
// pin 12 - Data/Command select (D/C) on an Huzzah ESP8266
// pin 5 - LCD chip select (CS)
// pin 4 - LCD reset (RST)
Adafruit_PCD8544 display = Adafruit_PCD8544(12, 5, 4);

// On my D1 Mini I have the following wired up:
// Screen to D1 Mini
// GND -> GND
// LIGHT -> D3
// VCC -> 3V
// CLK -> D5
// DIN -> D7
// DC -> D6
// CE -> D8
// RST -> D0

TetrisMatrixDraw tetris(display);

bool showColon = true;

boolean animate = true;

void animationHandler()
{
if (true) {
display.clearDisplay();
animate = !tetris.drawText(10, 30);
display.display();
}
}


void drawIntro(int x = 0, int y = 0)
{
tetris.drawChar("T", x, y, tetris.tetrisBLACK);
tetris.drawChar("e", x + 5, y, tetris.tetrisMAGENTA);
tetris.drawChar("t", x + 11, y, tetris.tetrisYELLOW);
tetris.drawChar("r", x + 17, y, tetris.tetrisGREEN);
tetris.drawChar("i", x + 22, y, tetris.tetrisBLUE);
tetris.drawChar("s", x + 27, y, tetris.tetrisRED);

tetris.drawChar("L", x - 2, y + 9, tetris.tetrisRED);
tetris.drawChar("e", x + 5, y + 9, tetris.tetrisMAGENTA);
tetris.drawChar("t", x + 11, y + 9, tetris.tetrisYELLOW);
tetris.drawChar("t", x + 17, y + 9, tetris.tetrisGREEN);
tetris.drawChar("e", x + 23, y + 9, tetris.tetrisBLUE);
tetris.drawChar("r", x + 29, y + 9, tetris.tetrisRED);
tetris.drawChar("s", x + 37, y + 9, tetris.tetrisMAGENTA);
}

void setup() {
Serial.begin(115200);
display.begin();
// init done

// you can change the contrast around to adapt the display
// for the best viewing!
display.setContrast(60);

// My "LIGHT" pin is wired to D3
// This turns the backlight on
pinMode(D3, OUTPUT);
digitalWrite(D3, LOW);

yield();

drawIntro(10, 10);

delay(2000);

// Scale causing a crash for me, no idea why?
// tetris.scale = 2;

// Must use upercase characters
// See below for all supported chars

tetris.setText("HELLO!");

animationTicker.attach(0.05, animationHandler);


delay(10000);
animate = true;
tetris.setText("!#$%&'()");

delay(10000);
animate = true;
tetris.setText("*+,-./");

delay(10000);
animate = true;
tetris.setText("01234567");

delay(10000);
animate = true;
tetris.setText("89:;<=>?");

delay(10000);
animate = true;
tetris.setText("@ABCDEFG");

delay(10000);
animate = true;
tetris.setText("HIJKLMNO");

delay(10000);
animate = true;
tetris.setText("PQRSTUVW");

delay(10000);
animate = true;
tetris.setText("XYZ");


}


void loop() {
}
152 changes: 152 additions & 0 deletions examples/VgaEsp32Lib/ESP32/AlphaTestVGA/AlphaTestVGA
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
/*******************************************************************
Example showing writing text using the TetrisAnimation
library on a VGA Screen using Bitluni's ESP32Lib for the ESP32.
*
For Use with products from Bitluni's Tindie:
https://www.tindie.com/stores/bitluni/
*
Written by Brian Lough (witnessmenow on Github)

*******************************************************************/

// ----------------------------
// Standard Libraries - Already Installed if you have ESP32 set up
// ----------------------------

// ----------------------------
// Additional Libraries - each one of these will need to be installed.
// ----------------------------

// The 3 includes below all belong to Bitluni ESP32Lib
// They are being used to interface with the VGA
// Can be installed from the library manager (Search for Bitluni)
// https://github.com/adafruit/Adafruit-GFX-Library
#include <ESP32Lib.h>
#include <Ressources/Font6x8.h>
#include <GfxWrapper.h>

// Adafruit GFX library is a dependancy for the GfxWrapper
// Can be installed from the library manager
// https://github.com/adafruit/Adafruit-GFX-Library

#include <TetrisMatrixDraw.h>
// This library!
// https://github.com/toblum/TetrisAnimation


portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;

hw_timer_t * animationTimer = NULL;

//VGA Device
VGA6Bit vga;
GfxWrapper<VGA6Bit> gfx(vga, 320, 200);

TetrisMatrixDraw tetris(gfx);

bool showColon = true;

#define ANIMATION_TIME 50000 // Controls the speed in which the blocks update,
// increase this number to make it slower

boolean animate = true;

void animationHandler()
{
portENTER_CRITICAL_ISR(&timerMux);
if(animate){
vga.clear(0);
animate = !tetris.drawText(25, 150);
vga.show();
}
portEXIT_CRITICAL_ISR(&timerMux);
}


void drawIntro(int x = 0, int y = 0)
{
tetris.drawChar("T", x, y, tetris.tetrisCYAN);
tetris.drawChar("e", x + 5, y, tetris.tetrisMAGENTA);
tetris.drawChar("t", x + 11, y, tetris.tetrisYELLOW);
tetris.drawChar("r", x + 17, y, tetris.tetrisGREEN);
tetris.drawChar("i", x + 22, y, tetris.tetrisBLUE);
tetris.drawChar("s", x + 27, y, tetris.tetrisRED);

tetris.drawChar("L", x - 2, y + 9, tetris.tetrisRED);
tetris.drawChar("e", x + 5, y + 9, tetris.tetrisMAGENTA);
tetris.drawChar("t", x + 11, y + 9, tetris.tetrisYELLOW);
tetris.drawChar("t", x + 17, y + 9, tetris.tetrisGREEN);
tetris.drawChar("e", x + 23, y + 9, tetris.tetrisBLUE);
tetris.drawChar("r", x + 29, y + 9, tetris.tetrisRED);
tetris.drawChar("s", x + 37, y + 9, tetris.tetrisMAGENTA);
}

void setup() {
Serial.begin(115200);
vga.setFrameBufferCount(2);

// You may need to change which board you are using:
// https://github.com/bitluni/ESP32Lib#predefined-pin-configurations
vga.init(vga.MODE320x200, vga.VGAv01);

yield();

drawIntro(10, 10); //This is tiny at this resolution!!!

delay(2000);

// Scaling each block that makes up to be 6 pixels wide
tetris.scale = 6;

// Drawing an outline around each block to give them defintion
tetris.outLineColour = 0x0000; // any RGB 565 colour, defaults to black anyways
tetris.drawOutline = true;

// Must use upercase characters
// See below for all supported chars
tetris.setText("HELLO!");

animationTimer = timerBegin(1, 80, true);
timerAttachInterrupt(animationTimer, &animationHandler, true);
timerAlarmWrite(animationTimer, ANIMATION_TIME, true);
timerAlarmEnable(animationTimer);


delay(10000);
animate = true;
tetris.setText("!#$%&'()");

delay(10000);
animate = true;
tetris.setText("*+,-./");

delay(10000);
animate = true;
tetris.setText("01234567");

delay(10000);
animate = true;
tetris.setText("89:;<=>?");

delay(10000);
animate = true;
tetris.setText("@ABCDEFG");

delay(10000);
animate = true;
tetris.setText("HIJKLMNO");

delay(10000);
animate = true;
tetris.setText("PQRSTUVW");

delay(10000);
animate = true;
tetris.setText("XYZ");


}


void loop() {
}
Loading

0 comments on commit d981d42

Please sign in to comment.