Last active
March 17, 2020 23:02
-
-
Save IdrisCytron/6398c2830361db2fc126a9f98c75fb45 to your computer and use it in GitHub Desktop.
IoT scoreboard using Teensy and ESP8266 with Arduino IDE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Tutorial: IoT scoreboard using Teensy and ESP8266 with Blynk app | |
Hardware: | |
- Teensy LC (Low Cost) Controller Board | |
https://my.cytron.io/p-teensy-lc-low-cost-controller-board?tracking=idris | |
- ESP-01 WiFi Serial Transceiver Module (ESP8266) | |
https://my.cytron.io/p-esp-01-wifi-serial-transceiver-module-esp8266?tracking=idris | |
- WS2812B NeoPixel 8x32 LED Panel-256 LED | |
https://my.cytron.io/p-ws2812b-neopixel-8x32-led-panel-256-led?tracking=idris | |
External libraries: | |
- Blynk by Volodymyr Shymanskyy Version 0.6.1 | |
- Adafruit GFX Library by Adafruit Version 1.7.5 | |
- Adafruit NeoPixel by Adafruit Version 1.3.4 | |
- Adafruit NeoMatrix by Adafruit Version 1.1.4 | |
Created by: | |
2 Mar 2020 Idris Zainal Abidin, Cytron Technologies | |
*/ | |
#define BLYNK_PRINT Serial | |
#include <ESP8266_Lib.h> | |
#include <BlynkSimpleShieldEsp8266.h> | |
#include <Adafruit_GFX.h> | |
#include <Adafruit_NeoMatrix.h> | |
#include <Adafruit_NeoPixel.h> | |
char auth[] = "YourAuthToken"; | |
char ssid[] = "YourNetworkName"; | |
char pass[] = "YourPassword"; | |
#define EspSerial Serial3 | |
#define ESP8266_BAUD 115200 | |
ESP8266 wifi(&EspSerial); | |
#define PIN 1 | |
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(32, 8, PIN, | |
NEO_MATRIX_TOP + NEO_MATRIX_LEFT + | |
NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG, | |
NEO_GRB + NEO_KHZ800); | |
const uint16_t colors[] = { | |
matrix.Color(255, 255, 255), // White | |
matrix.Color(255, 0, 0), // Red | |
matrix.Color(0, 0, 255) // Blue | |
}; | |
enum {WHITE, RED, BLUE}; | |
int x = matrix.width(); | |
int score1 = 0; | |
int score2 = 0; | |
boolean scoreUpdate = true; | |
BLYNK_WRITE(V0) | |
{ | |
score1 = param.asInt(); | |
scoreUpdate = true; | |
} | |
BLYNK_WRITE(V1) | |
{ | |
score2 = param.asInt(); | |
scoreUpdate = true; | |
} | |
BLYNK_WRITE(V2) | |
{ | |
if (param.asInt()) { | |
score1 = 0; | |
Blynk.virtualWrite(0, 0); | |
scoreUpdate = true; | |
} | |
} | |
BLYNK_WRITE(V3) | |
{ | |
if (param.asInt()) { | |
score2 = 0; | |
Blynk.virtualWrite(1, 0); | |
scoreUpdate = true; | |
} | |
} | |
void setup() | |
{ | |
Serial.begin(9600); | |
delay(10); | |
EspSerial.begin(ESP8266_BAUD); | |
delay(10); | |
matrix.begin(); | |
matrix.setTextWrap(false); | |
matrix.setBrightness(60); | |
matrix.setTextColor(colors[WHITE]); | |
matrix.setCursor(7, 0); | |
matrix.print(F("...")); | |
matrix.show(); | |
Blynk.begin(auth, wifi, ssid, pass); | |
// Scrolling display "Ready" | |
while (1) { | |
matrix.fillScreen(0); | |
matrix.setCursor(x, 0); | |
matrix.print(F("Ready")); | |
if (--x < -30) { | |
break; | |
} | |
matrix.show(); | |
delay(100); | |
} | |
} | |
void loop() | |
{ | |
Blynk.run(); | |
if (scoreUpdate == true) { | |
scoreUpdate = false; | |
matrix.fillScreen(0); | |
matrix.setTextColor(colors[RED]); | |
matrix.setCursor(0, 0); | |
matrix.print(score1); | |
matrix.setTextColor(colors[WHITE]); | |
matrix.setCursor(13, 0); | |
matrix.print(F("-")); | |
matrix.setTextColor(colors[BLUE]); | |
if (score2 < 10) { | |
matrix.setCursor(26, 0); | |
} | |
else { | |
matrix.setCursor(20, 0); | |
} | |
matrix.print(score2); | |
matrix.show(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment