Created
December 17, 2018 20:37
-
-
Save hellvesper/14b8da714ccf6c84c9a25c2ea61cdec1 to your computer and use it in GitHub Desktop.
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
#include <Arduino.h> | |
#include <ESP8266WiFi.h> | |
#include <WiFiUdp.h> | |
#include <NTPClient.h> | |
#include "power.h" | |
// #include <SPI.h> | |
#include "LedControl.h" | |
#define RMS_CALIBRATION 1.21; // Sin Wave Form Factor pi/2√2 ≈ 1.11 | |
//the opcodes the MAX7221 and MAX7219 understand | |
// #define OP_NOOP 0 | |
// #define OP_DIGIT0 1 | |
// #define OP_DIGIT1 0 | |
// #define OP_DIGIT2 3 | |
// #define OP_DIGIT3 7 | |
// #define OP_DIGIT4 4 | |
// #define OP_DIGIT5 6 | |
// #define OP_DIGIT6 7 | |
// #define OP_DIGIT7 8 | |
// #define OP_DECODEMODE 9 | |
// #define OP_INTENSITY 10 | |
// #define OP_SCANLIMIT 11 | |
// #define OP_SHUTDOWN 12 | |
// #define OP_DISPLAYTEST 15 | |
const char *ssid = "****"; | |
const char *password = "****"; | |
WiFiUDP ntpUDP; | |
// By default 'pool.ntp.org' is used with 60 seconds update interval and | |
// no offset | |
NTPClient timeClient(ntpUDP, "router.lan"); | |
// You can specify the time server pool and the offset, (in seconds) | |
// additionaly you can specify the update interval (in milliseconds). | |
// NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 3600, 60000); | |
// int sps = TEST_CONST; | |
// static void reverseMemcpy(void *dst, void *src, size_t count) | |
// { | |
// uint8_t *s = (uint8_t *)src; | |
// while (count-- > 0) | |
// *((uint8_t *)dst + count) = *s++; | |
// } | |
LedControl lc = LedControl(D7, D5, D8, 1); | |
/* we always wait a bit between updates of the display */ | |
unsigned long delaytime = 250; | |
void setup() { | |
Serial.begin(115200); | |
WiFi.begin(ssid, password); | |
while (WiFi.status() != WL_CONNECTED) | |
{ | |
delay(500); | |
Serial.print("."); | |
} | |
timeClient.begin(); | |
power_init(ADS1115_DR_860SPS, GAIN_FOUR, 50); | |
// SPI config | |
lc.shutdown(0, false); | |
lc.setScanLimit(0,3); | |
/* Set the brightness to a medium values */ | |
lc.setIntensity(0, 8); | |
/* and clear the display */ | |
lc.clearDisplay(0); | |
// LedControl.shutdown() | |
// pinMode(D8, OUTPUT); | |
// digitalWrite(D8, HIGH); | |
// SPI.setBitOrder(MSBFIRST); | |
// SPI.begin(); | |
// SPI.pins(D5, D6, D7, D8); | |
// SPI.setHwCs(true); | |
// SPI.setDataMode(SPI_MODE0); // MODE 0 default | |
} | |
void drawChar(uint8_t dig, char ch, bool dp) | |
{ | |
switch (ch) | |
{ | |
case 'P': | |
// lc.setChar(0, dig, 'P', dp); | |
lc.setLed(0, dig, 1, dp); | |
lc.setLed(0, dig, 2, dp); | |
lc.setLed(0, dig, 5, dp); | |
lc.setLed(0, dig, 6, dp); | |
lc.setLed(0, dig, 7, dp); | |
break; | |
case 'r': | |
lc.setLed(0, dig, 5, dp); | |
lc.setLed(0, dig, 7, dp); | |
break; | |
case 'o': | |
lc.setLed(0, dig, 3, dp); | |
lc.setLed(0, dig, 4, dp); | |
lc.setLed(0, dig, 5, dp); | |
lc.setLed(0, dig, 7, dp); | |
break; | |
case 'H': | |
// lc.setChar(0,dig, 'H', dp); | |
lc.setLed(0, dig, 2, dp); | |
lc.setLed(0, dig, 3, dp); | |
lc.setLed(0, dig, 5, dp); | |
lc.setLed(0, dig, 6, dp); | |
lc.setLed(0, dig, 7, dp); | |
break; | |
case 'h': | |
lc.setLed(0, dig, 3, dp); | |
lc.setLed(0, dig, 5, dp); | |
lc.setLed(0, dig, 6, dp); | |
lc.setLed(0, dig, 7, dp); | |
break; | |
case 'i': // I | |
lc.setLed(0, dig, 5, dp); | |
lc.setLed(0, dig, 6, dp); | |
break; | |
case 'I': // I | |
lc.setLed(0, dig, 5, dp); | |
lc.setLed(0, dig, 6, dp); | |
break; | |
case 't': | |
lc.setLed(0, dig, 4, dp); | |
lc.setLed(0, dig, 5, dp); | |
lc.setLed(0, dig, 6, dp); | |
lc.setLed(0, dig, 7, dp); | |
break; | |
case 'e': // E | |
lc.setLed(0, dig, 1, dp); | |
lc.setLed(0, dig, 4, dp); | |
lc.setLed(0, dig, 5, dp); | |
lc.setLed(0, dig, 6, dp); | |
lc.setLed(0, dig, 7, dp); | |
break; | |
case 'E': // E | |
lc.setLed(0, dig, 1, dp); | |
lc.setLed(0, dig, 4, dp); | |
lc.setLed(0, dig, 5, dp); | |
lc.setLed(0, dig, 6, dp); | |
lc.setLed(0, dig, 7, dp); | |
break; | |
case 'c': | |
lc.setLed(0, dig, 4, dp); | |
lc.setLed(0, dig, 5, dp); | |
lc.setLed(0, dig, 7, dp); | |
break; | |
case '-': | |
lc.setLed(0, dig, 7, dp); | |
break; | |
case ' ': | |
lc.setLed(0, dig, 1, false); | |
lc.setLed(0, dig, 2, false); | |
lc.setLed(0, dig, 3, false); | |
lc.setLed(0, dig, 4, false); | |
lc.setLed(0, dig, 5, false); | |
lc.setLed(0, dig, 6, false); | |
lc.setLed(0, dig, 7, false); | |
lc.setLed(0, dig, 8, false); | |
break; | |
default: | |
break; | |
} | |
} | |
void loop() { | |
// calc(); | |
// timeClient.update(); | |
// Serial.println(timeClient.getHours()); | |
// Serial.println(timeClient.getFormattedTime()); | |
// SPI.beginTransaction(SPISettings(100000, MSBFIRST, SPI_MODE0)); | |
// uint16_t Dig1 = (1 << 8) + 1; // - | |
// uint16_t Dig2 = (2 << 8) + 1; // - | |
// uint16_t Dig3 = (3 << 8) + 1; // - | |
// uint16_t Dig4 = (4 << 8) + 1; // - | |
// Serial.println(Dig1); | |
// Serial.println(Dig2); | |
// Serial.println(Dig3); | |
// Serial.println(Dig4); | |
// digitalWrite(D8, LOW); | |
// SPI.transfer(&Dig1, sizeof(Dig1)); | |
// SPI.transfer(&Dig2, sizeof(Dig2)); | |
// SPI.transfer(&Dig3, sizeof(Dig3)); | |
// SPI.transfer(&Dig4, sizeof(Dig4)); | |
// digitalWrite(D8, HIGH); | |
// delay(100); | |
// if (timeClient.getSeconds() % 2 == 0) { | |
// /* code */ | |
// // digitalWrite(D8, HIGH); | |
// Serial.println("Even"); | |
// // Serial.print("Data: "); | |
// // Serial.println(val16); | |
// // Serial.print("Response: "); | |
// // Serial.println(response); | |
// } else { | |
// // digitalWrite(D8, LOW); | |
// Serial.println("Odd"); | |
// // Serial.print("Data: "); | |
// // Serial.println(val16); | |
// // Serial.print("Response: "); | |
// // Serial.println(response); | |
// } | |
// SPI.endTransaction(); | |
// writeArduinoOn7Segment(); | |
// scrollDigits(); | |
// lc.setChar(0, OP_DIGIT1, '1', false); | |
// lc.setChar(0, OP_DIGIT2, '2', false); | |
// lc.setChar(0, OP_DIGIT3, '3', false); | |
// lc.setChar(0, OP_DIGIT4, '4', false); | |
// lc.setLed(0, OP_DIGIT1, 0, true); | |
// for(size_t i = 0; i <= 7; i++) | |
// { | |
// lc.setLed(0, OP_DIGIT1, i, true); | |
// delay(500); | |
// } | |
// lc.clearDisplay(0); | |
/// ANIMATION | |
lc.clearDisplay(0); | |
for(size_t i = 0; i < 4; i++) | |
{ | |
lc.setLed(0, i, 1, true); // A | |
delay(100); | |
} | |
lc.setLed(0, 3, 2, true); // B | |
delay(100); | |
lc.setLed(0, 3, 3, true); // C | |
for (int i = 3; i >= 0; i--) | |
{ | |
lc.setLed(0, i, 4, true); // D | |
delay(100); | |
} | |
lc.setLed(0, 0, 5, true); // E | |
delay(100); | |
lc.setLed(0, 0, 6, true); // F | |
delay(100); | |
lc.clearDisplay(0); | |
// ========= | |
// char testStr[] = "ProHhIitech"; | |
// size_t chars = strlen(testStr); | |
// for(size_t i = 0; i < chars; i++) | |
// { | |
// for(size_t n = 0; n < 4; n++) | |
// { | |
// drawChar(n, testStr[i], true); | |
// delay(100); | |
// drawChar(n, testStr[i], false); | |
// } | |
// lc.clearDisplay(0); | |
// } | |
// Pro | |
for(int i = 3; i > 0; i--) | |
{ | |
drawChar(i, 'P', true); | |
delay(100); | |
drawChar(i, 'P', false); | |
} | |
drawChar(0, 'P', true); | |
delay(100); | |
for (int i = 3; i > 1; i--) | |
{ | |
drawChar(i, 'r', true); | |
delay(100); | |
drawChar(i, 'r', false); | |
} | |
drawChar(1, 'r', true); | |
delay(100); | |
for (int i = 3; i > 2; i--) | |
{ | |
drawChar(i, 'o', true); | |
delay(100); | |
drawChar(i, 'o', false); | |
} | |
drawChar(2, 'o', true); | |
delay(500); | |
lc.clearDisplay(0); | |
// Hi | |
drawChar(1, 'H', true); | |
drawChar(2, 'i', true); | |
delay(700); | |
lc.clearDisplay(0); | |
// tech | |
drawChar(0, 't', true); | |
delay(300); | |
drawChar(2, 'c', true); | |
delay(300); | |
drawChar(3, 'h', true); | |
delay(300); | |
drawChar(1, 'e', true); | |
delay(700); | |
lc.clearDisplay(0); | |
// Pro Hi-tEch | |
char pht[] = " Pro Hi-tech "; | |
for(size_t i = 5; i <= strlen(pht); i++) | |
{ | |
drawChar(0, pht[i - 4], true); | |
drawChar(1, pht[i - 3], true); | |
drawChar(2, pht[i - 2], true); | |
drawChar(3, pht[i - 1], true); | |
delay(200); | |
lc.clearDisplay(0); | |
} | |
delay(1000); | |
lc.clearDisplay(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment