Adding color markup

This commit is contained in:
Lukas Bachschwell 2017-12-14 17:12:33 +01:00
parent e3b7976781
commit cbdf93e7ee

View File

@ -13,6 +13,7 @@
#define HOST "bici.lbsfilm.at" #define HOST "bici.lbsfilm.at"
#define REFRESH 1000 #define REFRESH 1000
#define CHANGE_MODE 10000
#define OFFSET 1 #define OFFSET 1
@ -38,7 +39,9 @@ byte digits[12][7] = {
{ 0, 0, 1, 1, 1, 1, 0 } // Digit C { 0, 0, 1, 1, 1, 1, 0 } // Digit C
}; };
long oldTime = 0; long oldTime = 0; // for refresh
long oldModeTime = 0; // for mode
String bicislots = ""; String bicislots = "";
String bicis = ""; String bicis = "";
@ -48,14 +51,20 @@ String minutes = "";
char stationId[6] = "93"; char stationId[6] = "93";
bool displayOn = false; bool displayOn = false;
#define TIME 0
#define BICIS 1
unsigned int displayMode = TIME;
//flag for saving data //flag for saving data
bool shouldSaveConfig = false; bool shouldSaveConfig = false;
//callback notifying us of the need to save config //callback notifying us of the need to save config
void saveConfigCallback () { /*
void saveConfigCallback () {
Serial.println("Should save config"); Serial.println("Should save config");
shouldSaveConfig = true; shouldSaveConfig = true;
} }
*/
void setup() { void setup() {
Serial.begin(115200); Serial.begin(115200);
@ -66,7 +75,7 @@ void setup() {
WiFiManagerParameter custom_station_id("server", "station id", stationId, 6); WiFiManagerParameter custom_station_id("server", "station id", stationId, 6);
WiFiManager wifiManager; WiFiManager wifiManager;
wifiManager.setSaveConfigCallback(saveConfigCallback); //wifiManager.setSaveConfigCallback(saveConfigCallback);
wifiManager.autoConnect("ConfigureClock"); wifiManager.autoConnect("ConfigureClock");
wifiManager.addParameter(&custom_station_id); wifiManager.addParameter(&custom_station_id);
Serial.println(custom_station_id.getValue()); Serial.println(custom_station_id.getValue());
@ -90,12 +99,33 @@ void loop() // Main loop
{ {
// Check motion sensor // Check motion sensor
// get data and time // get data and time
displayOn = digitalRead(D6); displayOn = digitalRead(D7);
//displayOn = true;
if (millis() - oldModeTime > CHANGE_MODE) {
if (displayMode == TIME) displayMode = BICIS;
else displayMode = TIME;
oldModeTime = millis();
}
if (millis() - oldTime > REFRESH) { if (millis() - oldTime > REFRESH) {
uint32_t c = clock.Color(10, 10, 10);
getData(); getData();
if(displayOn) displayNumber(hours + ":" + minutes, c); switch (displayMode) {
case TIME: {
uint32_t c = clock.Color(100, 100, 130);
if (displayOn) displayNumber(hours + ":" + minutes, c);
else colorWipe( clock.Color(0, 0, 0), 1);
break;
}
case BICIS: {
uint32_t cSlots = clock.Color(100, 0, 0);
uint32_t cBicis = clock.Color(0, 100, 0);
if (displayOn) display2Numbers(bicislots, bicis, cSlots, cBicis );
else colorWipe( clock.Color(0, 0, 0), 1);
break;
}
}
Serial.println(hours + ":" + minutes); Serial.println(hours + ":" + minutes);
} }
} }
@ -103,7 +133,8 @@ void loop() // Main loop
void getData() { void getData() {
HTTPClient https; HTTPClient https;
String URL = "https://" + String(HOST) + "/stations?stationId=" + String(STATION_UID); String URL = "https://" + String(HOST) + "/stations?stationId=" + String(STATION_UID);
https.begin( URL, "1D:62:C5:06:5E:45:51:26:2F:56:A5:BD:E9:5E:F1:33:C8:6C:66:05"); //HTTPS Serial.println(URL);
https.begin( URL, "20:0F:86:A4:96:D4:40:EF:28:03:C4:36:B7:B5:F2:C3:55:42:E7:51"); //HTTPS
int httpCode = https.GET(); int httpCode = https.GET();
if (httpCode > 0) { if (httpCode > 0) {
@ -256,6 +287,19 @@ void displayNumber(String string, uint32_t color) {
} }
void display2Numbers(String string, String string2, uint32_t color, uint32_t color2 ) {
for (int i = 0; i < 2; i++) {
fillNumber(i, string[i] - 48, color);
}
for (int i = 0; i < 2; i++) {
fillNumber(i + 2, string2[i] - 48, color2);
}
nocolon();
}
void noclock() { void noclock() {
for (int led = 0; led < clock.numPixels(); led++) { for (int led = 0; led < clock.numPixels(); led++) {
clock.setPixelColor(led, 0); clock.setPixelColor(led, 0);
@ -299,17 +343,17 @@ void fillNumber(int position, int digit, uint32_t color) {
} }
void countUp(uint32_t color, int wait) { void countUp(uint32_t color, int wait) {
fillNumber(0, 8, clock.Color(0,0,0)); fillNumber(0, 8, clock.Color(0, 0, 0));
for (int num3 = 0; num3 < 10; num3++) { for (int num3 = 0; num3 < 10; num3++) {
fillNumber(1, num3, color); fillNumber(1, num3, color);
for (int num2 = 0; num2 < 10; num2++) { for (int num2 = 0; num2 < 10; num2++) {
fillNumber(2, num2, color); fillNumber(2, num2, color);
for (int num1 = 0; num1 < 10; num1++) { for (int num1 = 0; num1 < 10; num1++) {
fillNumber(3, num1, color); fillNumber(3, num1, color);
clock.show(); clock.show();
delay(wait); delay(wait);
} }