«ФЛЮГЕР». Погодная станция на ESP2866 и 1.8” дюймовом TFT экране.

«ФЛЮГЕР». Погодная станция на ESP2866 и 1.8” дюймовом TFT экране.

Погодная станция на базе ESP2866 и 1.8” дюймового TFT экрана (ST7533) с интернет подключением.

Доброго времени суток всем любителям повозиться с электронными поделками. Время осеннее, погода за окном капризная: то дождь, то ветер, а когда и то, и другое, да ещё и в одном флаконе. Оттого захотелось иметь под рукой устройство, которое само бы лазило за погодой в интернет, и таким образом не нужно было бы самому в мобильнике или компьютере искать, что думают об этой самой погоде метеорологи. Благо, они сейчас для всех желающих транслируют сводку погоды в интернет, а раньше шли метеосводки по радио на специально отведённых под это дело частотах и радисты на кораблях, геологических экспедициях и других службах записывали в ручную их бумаге, а в конторах отбивали на печатной машинке. Но сейчас это дело можно поручить микроконтроллеру и ESP2866 прекрасно с этим делом справляется. Всего-то и нужно, что подключить его по Wi-Fi к домашней сети, получить бесплатный ключ на странице http://openweathermap.org/api и научить микроконтроллер обрабатывать полученную информацию и отображать результат на 1.8” дюймовом цветном дисплее. Дисплей с контроллером ST7533 к микроконтроллеру ESP2866 подключается по I2C шине, поэтому проводов для соединения потребуется совсем не много. Запитан «флюгер» от старого зарядного устройства от мобильного телефона, а поместил его в коробочку от другой зарядки. Получилось довольно компактно. Заодно можно использовать в качестве ночничка на прикроватной тумбочке. По ходу получилось два варианта: аскетический с дополнительно индикацией точного времени, которое тоже берётся из интернета от google.com, плюс с датчика LM35 определяет температуру в помещении. Второй вариант — чисто погодный информатор с расширенной информационной табличкой. Для облегчения ориентации таблица снабжена цветными иконками. Итак, список контактов между микроконтроллером и дисплеем. TFT дисплей ESP2866 подключаем по шине SPI:

GND - GND

VCC - 3,3v

SCL - D1

SDA - D2

RES - D3

DC - D4

CS - D0

BL - D5

Ниже два варианта скетчей, которые при помощи программы Arduino IDE можно загрузить в микроконтроллер.

Аскетический вариант.

#include "Arduino.h"

#include <ArduinoJson.h>

#include <SPI.h>

#include <Adafruit_GFX.h>

#include <Adafruit_ST7735.h>// include Adafruit ST7735 TFT library

#define TFT_CS16 // PyBadge/PyGamer display control pins: chip select

#define TFT_RST0 // Display reset

#define TFT_DC2 // Display data/command select

#define TFT_BACKLIGHT 14 // Display backlight pin

#define TFT_MOSI 4// Data out

#define TFT_SCLK 5// Clock out

Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);

int a;

int b;

int c;

int raw = 0;

float temp = 0;

int tempin = 0;

int wtype = 9;

String icon;

String arr_weather[50]={"clear sky","few clouds","scattered clouds","broken clouds","!ND!","!ND!","!ND!","!ND!","shower rain","rain","thunderstorm","!ND!","snow","!ND!","!ND!","!ND!","!ND!","!ND!","!ND!","!ND!","!ND!","!ND!","!ND!","!ND!","!ND!","!ND!","!ND!","!ND!","!ND!","!ND!","!ND!","!ND!","!ND!","!ND!","!ND!","!ND!","!ND!","!ND!","!ND!","!ND!","!ND!","!ND!","!ND!","!ND!","!ND!","!ND!","!ND!","!ND!","!ND!","mist"};

WiFiClient client;

// Домен сервера, на который мы будем обращаться

const char server[] = "api.openweathermap.org";

String date;

int h,m,s;

const char *ssid= "Имя вашей сети";

const char *password = "Пароль вашей сети";

int last = 0;

// read OpenWeather api description for more info

// =======================================================================

const char *weatherHost = "api.openweathermap.org";

char weather_message[300];

char time_message[50];

char date_message[50];

void setup() {

Serial.begin(57600);

pinMode( A0, INPUT );

tft.initR(INITR_BLACKTAB);// Initialize ST7735R screen

tft.fillScreen(ST7735_BLACK);// fill screen with black color

//tft.drawFastHLine(0, 2,tft.width(), ST7735_WHITE);// draw horizontal white line at position (0, 0)

tft.drawFastHLine(0, 38,tft.width(), ST7735_WHITE);// draw horizontal white line at position (0, 76)

//tft.drawFastHLine(0, 57,tft.width(), ST7735_WHITE);// draw horizontal white line at position (0, 122)

tft.drawFastHLine(0, 85,tft.width(), ST7735_WHITE);// draw horizontal white line at position (0, 122)

//tft.drawFastHLine(0, 158,tft.width(), ST7735_WHITE);// draw horizontal white line at position (0, 122)

tft.setTextColor(ST7735_WHITE, ST7735_BLACK);// set text color to BLACK and black background

tft.setCursor(5, 7);// move cursor to position (25, 39) pixel

tft.print("IN");

tft.setTextSize(2);// text size = 2

// print °C

tft.drawCircle(75, 12, 2, ST7735_GREEN);// print degree symbol ( ° )

tft.setCursor(80, 12);// move cursor to position (95, 54) pixel

tft.setTextColor(ST7735_GREEN, ST7735_BLACK);// set text color to yellow and black background

tft.print("C");

tft.setTextSize(1);// text size = 1

tft.setTextColor(ST7735_WHITE, ST7735_BLACK);// set text color to cyan and black background

tft.setCursor(5, 150);// move cursor to position (34, 85) pixel

tft.print("OUT");

tft.setTextSize(2);// text size = 2

tft.drawCircle(55, 90, 2, ST7735_GREEN);// print degree symbol ( ° )

tft.setTextColor(ST7735_GREEN, ST7735_BLACK);// set text color to yellow and black background

tft.setCursor(60, 90);

tft.print("C");

tft.setTextSize(2);

tft.setCursor(60, 110);

tft.print("m/s");

tft.drawCircle(55, 132, 2, ST7735_GREEN);// print degree symbol ( ° )

Serial.print("Connecting WiFi ");

Serial.println("Booting");

WiFi.mode(WIFI_STA);

WiFi.begin(ssid, password);

while (WiFi.waitForConnectResult() != WL_CONNECTED) {

Serial.println("Connection Failed! Rebooting...");

delay(500);

ESP.restart();

}

getWeatherData();

}

// =======================================================================

// retrive weather data

char grada;

char gradb;

char gradc;

char winda;

char windb;

char windc;

char windd;

char wdira;

char wdirb;

char wdirc;

char icona;

char iconb;

char humia;

char humib;

char humic;

int i=0;

int j=0;

String weather_date = "";

void getWeatherData()

{

Serial.print("connecting to "); Serial.println(weatherHost);

if (client.connect(weatherHost, 80)) {

//client.println ("GET /data/2.5/weather?q=Jurmala&mode=xml&units=metric&appid=81b5fd79fed2a7c7af5953cb76a8e7e8");

client.println ("GET /data/2.5/weather?q=Jurmala&units=metric&appid=81b5fd79fed2a7c7af5953cb76a8e7e8");

//client.println("GET /data/2.5/weather?q=Jurmala&mode=xml&units=metric&appid=81b5fd79fed2a7c7af5953cb76a8e7e8");

client.print("Host: ");

client.println(server);

client.println("Connection: close");

client.println();

// Ждем, пока придет ответ

while (!client.available())

;

char symbol;

// Пока есть ответ...

while (client.available()) {

// Считываем принятый байт

symbol = client.read();

weather_date = (weather_date + symbol);

// Для отладки пишем его в консоль

Serial.print(symbol);

++i;

}

}

// останавливаем клиент

client.stop();

//Serial.println("");

//Serial.print("i=");

//Serial.println(i);

//Serial.println("weather_date");

//Serial.print(weather_date);

for (j=0; j<i; ++j) {

if (weather_date.charAt(j) == 'i') {

if (weather_date.charAt(j+1) == 'c') {

if (weather_date.charAt(j+2) == 'o') {

if (weather_date.charAt(j+3) == 'n') {

icona = weather_date.charAt(j+4);

icona = weather_date.charAt(j+5);

icona = weather_date.charAt(j+6);

icona = weather_date.charAt(j+7);

iconb = weather_date.charAt(j+8);

}

}

}

}

if (weather_date.charAt(j) == 'e') {

if (weather_date.charAt(j+1) == 'm') {

if (weather_date.charAt(j+2) == 'p') {

if (weather_date.charAt(j+3) == '"') {

if (weather_date.charAt(j+4) == ':') {

grada = weather_date.charAt(j+5);

gradb = weather_date.charAt(j+6);

gradc = weather_date.charAt(j+7);

if (gradb ==',' || gradb =='"') {

gradb = 32;}

if (gradc ==',' || gradc =='"') {

gradc = 32;}

}

}

}

}

}

if (weather_date.charAt(j) == 'd') {

if (weather_date.charAt(j+1) == 'i') {

if (weather_date.charAt(j+2) == 't') {

if (weather_date.charAt(j+3) == 'y') {

if (weather_date.charAt(j+4) == '"') {

if (weather_date.charAt(j+5) == ':') {

humia = weather_date.charAt(j+6);

humib = weather_date.charAt(j+7);

humic = weather_date.charAt(j+8);

if (humib =='}'|| humib ==',') {

humib = 32;}

if (humic =='}'|| humic ==',') {

humic = 32;}

}

}

}

}

}

}

if (weather_date.charAt(j) == 'e') {

if (weather_date.charAt(j+1) == 'e') {

if (weather_date.charAt(j+2) == 'd') {

if (weather_date.charAt(j+3) == '"') {

if (weather_date.charAt(j+4) == ':') {

winda = weather_date.charAt(j+5);

windb = weather_date.charAt(j+6);

windc = weather_date.charAt(j+7);

if (windb ==',' || windb =='"') {

windb = 32;}

if (windc ==',' || windc =='"') {

windc = 32;}

}

}

}

}

}

if (weather_date.charAt(j) == 'd') {

if (weather_date.charAt(j+1) == 'e') {

if (weather_date.charAt(j+2) == 'g') {

if (weather_date.charAt(j+3) == '"') {

wdira = weather_date.charAt(j+4);

wdira = weather_date.charAt(j+5);

wdirb = weather_date.charAt(j+6);

wdirc = weather_date.charAt(j+7);

}

}

}

}

}

if (wdirb =='}') {

wdirb = 32;}

if (wdirc =='}') {

wdirc = 32;}

}

// =======================================================================

float utcOffset = 2;

long localEpoc = 0;

long localMillisAtUpdate = 0;

void getTime()

{

WiFiClient client;

if (!client.connect("www.google.com", 80)) {

Serial.println("connection to google failed");

tft.setTextSize(1);// text size = 1

tft.setTextColor(ST7735_RED, ST7735_BLACK);// set text color to BLACK and black background

tft.setCursor(110, 5);// move cursor to position (25, 39) pixel

tft.write(8);

tft.setTextSize(2);// text size = 2

return;

}

client.print(String("GET / HTTP/1.1\r\n") +

String("Host: www.google.com\r\n") +

String("Connection: close\r\n\r\n"));

int repeatCounter = 0;

while (!client.available() && repeatCounter < 10) {

delay(500);

Serial.println("Connection to google OK");

tft.setTextSize(1);// text size = 1

tft.setTextColor(ST7735_GREEN, ST7735_BLACK);// set text color to BLACK and black background

tft.setCursor(110, 5);// move cursor to position (25, 39) pixel

tft.write(7);

tft.setTextSize(2);// text size = 2

repeatCounter++;

}

String line;

client.setNoDelay(false);

while(client.connected() && client.available()) {

line = client.readStringUntil('\n');

line.toUpperCase();

if (line.startsWith("DATE: ")) {

date = ""+line.substring(6, 22);

h = line.substring(23, 25).toInt();

m = line.substring(26, 28).toInt();

s = line.substring(29, 31).toInt();

localMillisAtUpdate = millis();

localEpoc = (h * 60 * 60 + m * 60 + s);

String clock_date = date;

int date_len = clock_date.length() + 1;

clock_date.toCharArray(date_message, date_len) ;

}

}

client.stop();

}

// =======================================================================

void updateTime()

{

long curEpoch = localEpoc + ((millis() - localMillisAtUpdate) / 1000);

//long epoch = round(curEpoch + 3600 * utcOffset + 86400L) % 86400L;

long epoch = round(curEpoch+ 3600 * utcOffset + 86400L);

h = ((epoch% 86400L) / 3600) % 24;

m = (epoch % 3600) / 60;

s = epoch % 60;

}

// =======================================================================

long lastmillis=millis();

void showTime()

{

String timeString = "";

timeString+= h/10 ? h/10 : 0;

timeString+= h%10;

timeString+= ":";

timeString+= m/10;

timeString+= m%10;

//timeString+= ":";

//timeString+= s/10;

//timeString+= s%10;

String clock_time = timeString;

int clock_len = clock_time.length() + 1;

clock_time.toCharArray(time_message, clock_len) ;

tft.setTextSize(2);// text size = 2

tft.setCursor(35, 60);

tft.setTextColor(ST7735_GREEN, ST7735_BLACK);// set text color to orange and black background

tft.print(clock_time);

Serial.print(clock_time);

}

void loop() {

getTime();

updateTime();

showTime();

tft.setTextSize(1);// text size = 1

tft.setCursor(18, 45);

tft.setTextColor(ST7735_GREEN, ST7735_BLACK);// set text color to orange and black background

tft.print(date);

tft.setTextSize(2);

tft.setCursor(10, 90);

tft.print(grada);

tft.setCursor(20, 90);

tft.print(gradb);

tft.setCursor(30, 90);

tft.print(gradc);

tft.setCursor(70, 130);

tft.print(humia);

tft.setCursor(80, 130);

tft.print(humib);

tft.setCursor(90, 130);

tft.print(humic);

tft.setCursor(102, 130);

tft.write(37);

tft.setCursor(10, 110);

tft.print(winda);

tft.setCursor(20, 110);

tft.print(windb);

tft.setCursor(30, 110);

tft.print(windc);

tft.setCursor(40, 110);

tft.print(windd);

tft.setCursor(10, 130);

tft.print(wdira);

tft.setCursor(25, 130);

tft.print(wdirb);

tft.setCursor(40, 130);

tft.print(wdirc);

tft.setTextSize(1);

tft.setTextColor(ST7735_WHITE, ST7735_BLACK);

tft.setCursor(30, 150);

a = (int)icona - 48;b = (int)iconb - 48;c=a*10+b-1;

tft.print(arr_weather[(int)c]);

tft.print("");

raw = analogRead(A0);

tempin = (( raw/1023.0 )*3.3*1000/13);

tft.setTextColor(ST7735_GREEN, ST7735_BLACK);

tft.setTextSize(2);// text size = 2

tft.setCursor(45, 12);

tft.print (tempin);

if((millis()- last)>1000*60*15){//update weather every 15 minutes

getWeatherData();

getTime();

last = millis();

}

}


Погодный информатор.

Каждые 15 минут обновляет с погодного сервера данные о погоде и выводит их на экран. Это сведения о температуре и влажности воздуха, силе и направлении ветра в градусах, степени покрытия неба облаками в процентах и видимость в метрах. Кроме того на экран выводится иконка с символом погодных условий. При силе ветра более шести баллов выводится иконка с предупреждением. Цвета иконок температуры, направления ветра и его силы меняются в зависимости от плюсовой или отрицательной температуры, а ветер южный или северный. Ниже скетч программы:

#include <ESP8266WiFi.h>

#include <Wire.h>

#include <Adafruit_GFX.h>

#include "icon.h" // 8-ми битные иконки, указывающие на тип данных

#include "oper.h" // 16-ти битные символы погоды

#include <ArduinoJson.h>

#include <Fonts/FreeSansBold12pt7b.h>

#include <Adafruit_GFX.h>

#include <Adafruit_ST7735.h>// include Adafruit ST7735 TFT library

#define TFT_CS16 // PyBadge/PyGamer tft control pins: chip select

#define TFT_RST0 // tft reset

#define TFT_DC2 // tft data/command select

#define TFT_BACKLIGHT 14 // tft backlight pin

#define TFT_MOSI 4// Data out

#define TFT_SCLK 5// Clock out

Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);

// =======================================================================

// Конфигурация устройства:

// =======================================================================

const char* ssid= "Имя вашего устройства";// SSID

const char* password = "Ваш пароль";// пароль

String weatherKey = "Идентификационный ключ";// Чтобы получить API ключ, перейдите по ссылке http://openweathermap.org/api

String weatherLang = "&lang=en";

String cityID = "Код вашего города";

// =======================================================================

WiFiClient client;

// ======================== Погодные переменные

String icon;

int humidity;

String humiditysum;

int pressure;

float temp;

String tempsum;

int degw;

String degwsum;

int clouds;

String cloudssum;

float windSpeed;

String windSpeedsum;

int visibility;

String visibilitysum;

String date;

String weatherString;

int last = 0;

int a, b, c;

void setup(){

/*setAddrWindow(uint16_t x, uint16_t y, uint16_t w,

uint16_t h) {

x += _xstart+2;

y += _ystart+2;

uint32_t xa = ((uint32_t)x << 16) | (x+w-1);

uint32_t ya = ((uint32_t)y << 16) | (y+h-1);

writeCommand(ST7735_CASET); // Column addr set

SPI_WRITE32(xa);

writeCommand(ST7735_RASET); // Row addr set

SPI_WRITE32(ya);

writeCommand(ST7735_RAMWR); // write to RAM

}*/

Serial.begin(115200);

// ======================== Соединение с WIFI

WiFi.mode(WIFI_STA);

WiFi.begin(ssid, password);// Подключаемся к WIFI

while (WiFi.status() != WL_CONNECTED) {// Ждем до посинения

delay(500);

}

Serial.println("WI-Fi OK");

// pinMode( A0, INPUT );

tft.initR(INITR_BLACKTAB);// Initialize ST7735R screen

tft.fillScreen(ST7735_BLACK);// fill screen with black color

tft.drawBitmap(5, 7, dom, 128, 145, ST7735_YELLOW);

delay(5000);

tft.fillScreen(ST7735_BLACK);// fill screen with black color

getTime();

updateTime();

getWeatherData();

}

// =========================== Переменные времени

int updCnt = 0;

int dots = 0;

long dotTime = 0;

long clkTime = 0;

int dx=0;

int dy=0;

byte del=0;

int h,m,s;

// =======================================================================

void loop() {

if((millis()- last)>1000*60*15){//update weather every 15 minutes

getTime();

updateTime();

last = millis();

getWeatherData();

}

updateTime();

if(millis()-dotTime > 500) {

dotTime = millis();

dots = !dots;

}

}

//========================================================================

void weather() {

tft.fillScreen(ST7735_BLACK);// fill screen with black color

tft.setTextSize(1);

tft.setTextColor(ST7735_GREEN);

tft.setCursor(0,0);

tft.setFont(&FreeSansBold12pt7b);

tft.setTextSize(1);

tft.setTextColor(ST7735_GREEN);

tft.setCursor(25,25);

tft.print(String(tempsum));

tft.setFont(&FreeSansBold12pt7b);

tft.setFont();

tft.setTextSize(1);

tft.setTextColor(ST7735_GREEN);

tft.setCursor(0,0);

//HUMI;

tft.setFont(&FreeSansBold12pt7b);

tft.setTextSize(1);

tft.setTextColor(ST7735_GREEN);

tft.setCursor(25,50);

tft.println(String(humiditysum));

tft.setTextColor(ST7735_GREEN);

tft.setCursor(25,75);

tft.println(String(windSpeedsum));

//WIND_DEG;

tft.setFont(&FreeSansBold12pt7b);

tft.setTextSize(1);

tft.setTextColor(ST7735_GREEN);

tft.setCursor(25,100);

tft.println(String(degwsum));

tft.setFont();

tft.setTextSize(1);

tft.setTextColor(ST7735_GREEN);

tft.setCursor(0,0);

//CLOUDS;

tft.setFont(&FreeSansBold12pt7b);

tft.setTextSize(1);

tft.setTextColor(ST7735_GREEN);

tft.setCursor(25,125);

tft.println(cloudssum);

tft.setFont();

tft.setTextSize(1);

tft.setFont();

tft.setTextSize(1);

tft.setTextColor(ST7735_GREEN);

tft.setCursor(0,0);

//visibility;

tft.setFont(&FreeSansBold12pt7b);

tft.setTextSize(1);

tft.setTextColor(ST7735_GREEN);

tft.setCursor(25,150);

tft.println(visibilitysum);

Serial.print ("Time:");

Serial.println(String(h/10)+String(h%10)+":"+String(m/10)+String(m%10));

icon_show ();

}

// =======================================================================

// Погода с сайта openweathermap.org

// =======================================================================

const char *weatherHost = "api.openweathermap.org";

int i=0;

String weather_date;

void getWeatherData()

{

Serial.print("connecting to "); Serial.println(weatherHost);

if (client.connect(weatherHost, 80)) {

client.println(String("GET /data/2.5/weather?id=") + cityID + "&units=metric&appid=" + weatherKey + "\r\n" +

"Host: " + weatherHost + "\r\nUser-Agent: ArduinoWiFi/1.1\r\n" +

"Connection: close\r\n\r\n");

//client.println ("GET /data/2.5/weather?q=Jurmala&units=metric&appid=81b5fd79fed2a7c7af5953cb76a8e7e8");

} else {

Serial.println("connection failed");

return;

}

// Ждем, пока придет ответ

while (!client.available())

;

char symbol;

weather_date="";

// Пока есть ответ...

while (client.available()) {

// Считываем принятый байт

symbol = client.read();

weather_date = (weather_date + symbol);

//Serial.print(symbol);

++i;

}

client.stop();

Serial.println ("weather_date=");

Serial.println (weather_date);

DynamicJsonBuffer jsonBuf; // Обрабатываем полученную информацию

JsonObject &root = jsonBuf.parseObject(weather_date);

if (!root.success())

{

Serial.println("parseObject() failed");

return;

}

temp = root["main"]["temp"];

humidity = root["main"]["humidity"];

visibility = root["visibility"];

//pressure = root["main"]["pressure"];

degw = root["wind"]["deg"];

icon = root["weather"].as<String>();

windSpeed = root["wind"]["speed"];

clouds = root["clouds"]["all"];

tempsum = String(temp,1) + "*" + "C";

humiditysum = String(humidity) + "%";

cloudssum = String(clouds) + "%";

windSpeedsum = String(windSpeed,1) + "m/s";

degwsum = String(degw) + "*";

visibilitysum= String (visibility)+"m";

char icona, iconb;

for (int j=0; j<200; ++j) {

if (icon.charAt(j) == 'i') {

if (icon.charAt(j+1) == 'c') {

if (icon.charAt(j+2) == 'o') {

if (icon.charAt(j+3) == 'n') {

if (icon.charAt(j+4) == '"') {

if (icon.charAt(j+5) == ':') {

if (icon.charAt(j+6) == '"') {

icona = icon.charAt(j+7);

iconb = icon.charAt(j+8);

a = (int)icona - 48;b = (int)iconb - 48;c=a*10+b;

}

}

}

}

}

}

}

}

weather();

}

// =======================================================================

// Время у GOOGLE

// =======================================================================

float utcOffset = 2; //поправка на часовой пояс

long localEpoc = 0;

long localMillisAtUpdate = 0;

void getTime()

{

WiFiClient client;

if (!client.connect("www.google.com", 80)) {

Serial.println("connection to google failed");

return;

}

client.print(String("GET / HTTP/1.1\r\n") +

String("Host: www.google.com\r\n") +

String("Connection: close\r\n\r\n"));

int repeatCounter = 0;

while (!client.available() && repeatCounter < 10) {

delay(500);

Serial.println("Google OK");

repeatCounter++;

}

String line;

client.setNoDelay(false);

while(client.connected() && client.available()) {

line = client.readStringUntil('\n');

line.toUpperCase();

if (line.startsWith("DATE: ")) {

date = ""+line.substring(6, 22);

h = line.substring(23, 25).toInt();

m = line.substring(26, 28).toInt();

s = line.substring(29, 31).toInt();

localMillisAtUpdate = millis();

localEpoc = (h * 60 * 60 + m * 60 + s);

}

}

client.stop();

}

// =======================================================================r

void updateTime()

{

long curEpoch = localEpoc + ((millis() - localMillisAtUpdate) / 1000);

//long epoch = round(curEpoch + 3600 * utcOffset + 86400L) % 86400L;

long epoch = round(curEpoch + 3600 * utcOffset + 86400L);

h = ((epoch% 86400L) / 3600) % 24;

m = (epoch % 3600) / 60;

s = epoch % 60;

}

int dn;

void icon_show () {

if (h > 4 && h <21) {

dn = 1;

}

else { dn = 0;}

tft.drawBitmap(2, 35, efh, 16, 18, ST7735_CYAN);// выводим изображение (X, Y, bmp, ширина, высота, цвет)

tft.drawBitmap(2, 115, efc, 18, 8, ST7735_WHITE);

tft.drawBitmap(2, 135, efd, 20, 15, ST7735_MAGENTA);

if (windSpeed > 14) {

tft.drawRGBBitmap(90, 25, sw, 28, 33);

tft.drawBitmap(2, 60, efw, 20, 16, ST7735_RED);}

else {

tft.drawBitmap(2, 60, efw, 20, 16, ST7735_WHITE);

}

if (temp > 0) {

tft.drawBitmap(5, 7, eft, 12, 20, ST7735_RED);}

else {

tft.drawBitmap(5, 7, eft, 12, 20, ST7735_CYAN);

}

if (degw > 90 && degw < 270){

tft.drawBitmap(3, 82, efk, 20, 20, ST7735_RED);}

else {

tft.drawBitmap(3, 82, efk, 20, 20, ST7735_CYAN);

}

if (c == 1 && dn == 1) {tft.drawRGBBitmap(80, 90, ia, 40, 38);}

if (c == 1 && dn == 0) {tft.drawRGBBitmap(80, 90, ian, 35, 39);}

if (c == 2 && dn == 1) {tft.drawRGBBitmap(80, 90, ib, 40, 38);}

if (c == 2 && dn == 0) {tft.drawRGBBitmap(80, 90, ibn, 39, 30);}

if (c == 2) {tft.drawRGBBitmap(80, 90, ib, 40, 30);}

if (c == 3) {tft.drawRGBBitmap(80, 90, ic, 40, 25);}

if (c == 4) {tft.drawRGBBitmap(80, 90, id, 40, 25);}

if (c == 9) {tft.drawRGBBitmap(80, 90, iar, 39, 38);}

if (c == 10) {tft.drawRGBBitmap(80, 90, ibr, 39, 36);}

if (c == 11) {tft.drawRGBBitmap(80, 90, icr, 40, 37);}

if (c == 13) {tft.drawRGBBitmap(80, 90, is, 35, 39);}

if (c == 50) {tft.drawRGBBitmap(80, 90, im, 40, 35);}

}

Для второго варианта погодной станции в папку со скетчем нужно разместить два файла icon.h и oper.h, в которых закодированы иконки и погодные символы, которые соответствуют информации об символах передаваемых погодным сервером. Иконки и символы вы можете создать сами, по своему вкусу в любом графическом редакторе. После чего их нужно будет конвертировать в восьмибитный и шестнадцатеричные коды. Желательные размеры для иконок 30х30 пикселей, а символов погоды 40х40 пикселей. Более точные размеры нужно будет указать в командных строках. В интернете есть он-лайн конверторы изображений. Например: http://www.rinkydinkelectronics.com/t_imageconverter565.php


22:15
Нет комментариев. Ваш будет первым!