každý okres jedna RGB LEDka.
Objednání a dokumentace viz: https://github.com/tomasbrincil/pcb_mapa_cr_1
Co se má zobrazit je definováno ve volitelném efektu. Aktuálně dvě různá zobrazení teplot z TMEP.CZ
Není problém dodělat další - třeba výsledky voleb, nebo cokoliv zobrazitelného "po okresech", nebo přidat "nějaké blikání"
yaml pro ESPHome:
Kód: Vybrat vše
esphome:
name: rgbcrmap
includes:
- wheel.h
on_boot:
priority: -100
then:
- script.execute: getTemperaturesData
esp32:
board: esp32doit-devkit-v1
# Enable logging
logger:
web_server:
# Enable Home Assistant API
api:
encryption:
key: "ZXINxDk5Sk8o4+dS6XveJ2qurVltdoWJKurU/mVevns="
ota:
password: "b93d1d0149cede226333702f570533e5"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Rgbcrmap Fallback Hotspot"
password: "BfPrNYK8vZ83"
captive_portal:
globals:
- id: tempData
type: String
restore_value: False
initial_value: '"{}"'
light:
- platform: neopixelbus
type: GRB
variant: WS2812
pin: GPIO13
# method:
num_leds: 77
name: "NeoPixel Light"
id: neo
default_transition_length:
seconds: 0
# - platform: fastled_clockless
# chipset: WS2812B
# pin: GPIO13
# # method:
# num_leds: 77
# rgb_order: GRB
# name: "NeoPixel Light"
# id: neo
# default_transition_length:
# seconds: 0
effects:
- addressable_color_wipe:
- addressable_color_wipe:
name: Color Wipe Effect With Custom Values
colors:
- red: 100%
green: 100%
blue: 100%
num_leds: 1
- red: 0%
green: 0%
blue: 0%
num_leds: 1
add_led_interval: 100ms
reverse: false
- addressable_lambda:
name: "Mapa teplot TMEP @tvoje___mama"
update_interval: 3000ms
lambda: |-
DynamicJsonDocument doc(6144);
Serial.println(id(tempData));
DeserializationError error = deserializeJson(doc, id(tempData));
if (error) {
Serial.print("deserializeJson() failed: ");
Serial.println(error.c_str());
return;
}
for (JsonObject item : doc.as<JsonArray>()) {
int ledIndex = item["id"]; // 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, ...
ledIndex -= 1;
double h = item["h"]; // -0.6, -4.3, -2.2, -1.5, -0.5, -0.5, 0.9, -0.4, -2.5, -0.5, -2.2, -3.4, -3.9, ...
int color = map(h, -15, 40, 170, 0);
//it[ledIndex] = Wheel(color);
it[ledIndex] = WheelAda(color); //Adafruit values - podivej se do wheel.h, jsou tam odkazy
serialPrintf("okres: %d, teplota: %f, barva rgb: (Wheel/WheelAda) %d/%d %d/%d %d/%d\n",ledIndex,h,Wheel(color)[0],WheelAda(color)[0],Wheel(color)[1],WheelAda(color)[1],Wheel(color)[2],WheelAda(color)[2]);
}
//id(neo).turn_on().set_brightness(0.99).perform();
- addressable_lambda:
name: "Mapa teplot TMEP @jirka1213"
update_interval: 3000ms
lambda: |-
double maxTemp = -99;
double minTemp = 99;
DynamicJsonDocument doc(6144);
Serial.println(id(tempData));
DeserializationError error = deserializeJson(doc, id(tempData));
if (error) {
Serial.print("deserializeJson() failed: ");
Serial.println(error.c_str());
return;
}
//Zjisti min a max teplotu pro mapping
for (JsonObject item : doc.as<JsonArray>()) {
double h = item["h"];
if (h < minTemp) minTemp = h;
if (h > maxTemp) maxTemp = h;
}
for (JsonObject item : doc.as<JsonArray>()) {
int ledIndex = item["id"]; // 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, ...
ledIndex -= 1;
double h = item["h"]; // -0.6, -4.3, -2.2, -1.5, -0.5, -0.5, 0.9, -0.4, -2.5, -0.5, -2.2, -3.4, -3.9, ...
int color = map(h, minTemp, maxTemp, 170, 0);
//it[ledIndex] = Wheel(color);
it[ledIndex] = WheelAda(color); //Adafruit values - podivej se do wheel.h, jsou tam odkazy
serialPrintf("okres: %d, teplota: %f, barva rgb: (Wheel/WheelAda) %d/%d %d/%d %d/%d\n",ledIndex,h,Wheel(color)[0],WheelAda(color)[0],Wheel(color)[1],WheelAda(color)[1],Wheel(color)[2],WheelAda(color)[2]);
}
//id(neo).turn_on().set_brightness(0.99).perform();
json:
http_request:
id: http_request_data
useragent: esphome/rgbcrmap
timeout: 10s
async_tcp:
# https://arduinojson.org/v6/assistant/#/step1
time:
- platform: sntp
on_time:
- seconds: 0
minutes: /10
then:
- script.execute: getTemperaturesData
script:
- id: getTemperaturesData
mode: queued
then:
- logger.log:
level: info
format: "HTTP Request get Data"
- http_request.get:
url: "http://cdn.tmep.cz/app/export/okresy-cr-teplota.json"
headers:
Content-Type: application/json
verify_ssl: false
on_response:
- if:
condition:
lambda: |-
return status_code == 200;
then:
- logger.log:
level: info
tag: "getTemperaturedata"
format: "Response status: %d, Duration: %u ms"
args:
- status_code
- duration_ms
- lambda: |-
//String tempData;
id(tempData) = id(http_request_data).get_string();
Kód wheel.h:
soubor uložit tam kde je yaml
Kód: Vybrat vše
// https://votecharlie.com/blog/2018/08/improved-color-wheel-function.html
// Adapted from https://www.stm32duino.com/viewtopic.php?t=56#p8160
unsigned int sqrt32(unsigned long n) {
unsigned int c = 0x8000;
unsigned int g = 0x8000;
while(true) {
if(g*g > n) {
g ^= c;
}
c >>= 1;
if(c == 0) {
return g;
}
g |= c;
}
}
// Input values 0 to 255 to get color values that transition R->G->B. 0 and 255
// are the same color. This is based on Adafruit's Wheel() function, which used
// a linear map that resulted in brightness peaks at 0, 85 and 170. This version
// uses a quadratic map to make values approach 255 faster while leaving full
// red or green or blue untouched. For example, Wheel(42) is halfway between
// red and green. The linear function yielded (126, 129, 0), but this one yields
// (219, 221, 0). This function is based on the equation the circle centered at
// (255,0) with radius 255: (x-255)^2 + (y-0)^2 = r^2
Color Wheel(byte position) {
byte R = 0, G = 0, B = 0;
if (position < 85) {
R = sqrt32((1530 - 9 * position) * position);
G = sqrt32(65025 - 9 * position * position);
} else if (position < 170) {
position -= 85;
R = sqrt32(65025 - 9 * position * position);
B = sqrt32((1530 - 9 * position) * position);
} else {
position -= 170;
G = sqrt32((1530 - 9 * position) * position);
B = sqrt32(65025 - 9 * position * position);
}
return Color(R, G, B);
}
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
Color WheelAda(byte WheelPos) {
WheelPos = 255 - WheelPos;
if(WheelPos < 85) {
return Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if(WheelPos < 170) {
WheelPos -= 85;
return Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
//https://medium.com/@kslooi/print-formatted-data-in-arduino-serial-aaea9ca840e3
#include <stdarg.h>
#define SERIAL_PRINTF_MAX_BUFF 256
void serialPrintf(const char *fmt, ...);
void serialPrintf(const char *fmt, ...) {
/* Buffer for storing the formatted data */
char buff[SERIAL_PRINTF_MAX_BUFF];
/* pointer to the variable arguments list */
va_list pargs;
/* Initialise pargs to point to the first optional argument */
va_start(pargs, fmt);
/* create the formatted data and store in buff */
vsnprintf(buff, SERIAL_PRINTF_MAX_BUFF, fmt, pargs);
va_end(pargs);
Serial.print(buff);
}