Skip to content

Instantly share code, notes, and snippets.

@taniki
Created October 2, 2016 00:10
Show Gist options
  • Save taniki/80c82a872824e392ce5c663af84895ea to your computer and use it in GitHub Desktop.
Save taniki/80c82a872824e392ce5c663af84895ea to your computer and use it in GitHub Desktop.
# bitclock
#include <TimeLib.h>
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <NTPClient.h>
#include <BlynkSimpleEsp8266.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
// #include <avr/power.h> // Comment out this line for non-AVR boards (Arduino Due, etc.)
#define PIN D6
#define REFRESH 100
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 7200);
char ssid[] = "NETWORK NAME";
char pass[] = "NETWORK PASSWORD";
char auth[] = "BLYNK KEY";
int current_hour = 0;
int current_minute = 0;
uint32_t hour_color;
uint32_t minute_color;
int brightness = 32;
int default_color_hour[3] = { 100, 100, 0 };
int default_color_minutes[3] = { 100, 0, 100 };
int default_color_seconds[3] = { 0, 100, 100 };
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(8, 8, PIN,
NEO_MATRIX_TOP + NEO_MATRIX_RIGHT +
NEO_MATRIX_COLUMNS + NEO_MATRIX_PROGRESSIVE,
NEO_GRB + NEO_KHZ800);
void setup() {
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
// WiFi.begin(ssid, pass);
while ( WiFi.status() != WL_CONNECTED ) {
delay ( 500 );
Serial.print ( "." );
}
timeClient.begin();
matrix.begin();
matrix.setBrightness(brightness);
matrix.show(); // Initialize all pixels to 'off'
hour_color = matrix.Color(255, 0, 0);
minute_color = matrix.Color(255, 0, 0);
Blynk.virtualWrite(V0, default_color_hour[0], default_color_hour[1], default_color_hour[2]);
Blynk.virtualWrite(V1, default_color_minutes[0], default_color_minutes[1], default_color_minutes[2]);
Blynk.virtualWrite(V2, default_color_seconds[0], default_color_seconds[1], default_color_seconds[2]);
// Blynk.virtualWrite(0, default_color_hour);
// Blynk.virtualWrite(1, default_color_minutes);
// Blynk.virtualWrite(2, default_color_seconds);
}
BLYNK_WRITE(V3)
{
brightness = param.asInt();
}
void loop() {
timeClient.update();
Blynk.run();
matrix.setBrightness(brightness);
matrix.fillScreen(matrix.Color(0, 0, 0));
display_time();
matrix.show();
delay(200);
}
void display_time(){
drawInt(day(timeClient.getEpochTime()), 1, matrix.Color(100, 100, 100));
drawInt(month(timeClient.getEpochTime()), 2, matrix.Color(100, 100, 100));
drawInt(timeClient.getHours(), 4, matrix.Color(100, 100, 0));
drawInt(timeClient.getMinutes(), 5, matrix.Color(100, 0, 100));
drawInt(timeClient.getSeconds(), 6, matrix.Color(0, 100, 100));
}
void drawInt(int val, int y, uint32_t color){
String str = String(val, BIN);
for(int x = str.length(); x--; x==0){
if (str[x] == '1') matrix.drawPixel(x+1+6-str.length(), y, color);
// else matrix.drawPixel(x+1+6-str.length(), y, matrix.Color(50, 50, 50));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment