Технический Директор ![](https://radio-hobby.org/uploads/ranks/rank4ea58f675aa92.png)
Зарегистрирован: 08.02.2009 21:08
Из: Днестровск
|
Добавлен трёхцветный светодиод с ограничивающим ток резистором в 1 кОм. Теперь, если: жарко он мигает красным светом, тепло - горит красный, комфортно - горит зелёный, прохладно - горит синий, холодно - мигает синим светом. Также ограничена по времени продолжительность тревожного сигнала, до 15 секунд. Дополнительно при сильном ветре от 10,7 м/с и выше, начнёт мигать красный светодиод встроенный на самой плате Arduino Uno. Обновлённый проект для программы FLProg предоставлен в архиве к сообщению. ![Открыть изображение в новом окне](http://viy19.ucoz.ru/_ph/1/403702908.jpg)
#include <LiquidCrystalRus.h>
#include "DHT_NEW.h"
DHT _dht1;
LiquidCrystalRus disp(6, 7, 9, 10, 4, 5);
int _dispTempLength1=0;
boolean _isNeedClearDisp1;
int _disp23oldLength = 0;
int _disp6oldLength = 0;
int _disp8oldLength = 0;
int _disp15oldLength = 0;
unsigned long _SCT_2 = 0UL;
unsigned long _SCT_2IC = 0UL;
unsigned long _SCT_2P = 0UL;
int _disp18oldLength = 0;
int _disp21oldLength = 0;
unsigned long _dht1LRT = 0UL;
unsigned long _dht1Tti = 0UL;
int _disp30oldLength = 0;
int _disp20oldLength = 0;
int _disp24oldLength = 0;
int _BytesToWord_3_Out = 0;
bool _gen5I = 0;
bool _gen5O = 0;
unsigned long _gen5P = 0UL;
bool _gen4I = 0;
bool _gen4O = 0;
unsigned long _gen4P = 0UL;
int _disp22oldLength = 0;
int _disp2oldLength = 0;
int _disp27oldLength = 0;
int _disp5oldLength = 0;
int _disp10oldLength = 0;
int _disp25oldLength = 0;
int _disp3oldLength = 0;
int _disp1oldLength = 0;
int _disp29oldLength = 0;
int _disp32oldLength = 0;
int _BytesToWord_1_Out = 0;
bool _gen2I = 0;
bool _gen2O = 0;
unsigned long _gen2P = 0UL;
int _disp28oldLength = 0;
int _disp4oldLength = 0;
int _disp7oldLength = 0;
int _disp9oldLength = 0;
int _disp12oldLength = 0;
int _disp17oldLength = 0;
bool _gen1I = 0;
bool _gen1O = 0;
unsigned long _gen1P = 0UL;
int _disp11oldLength = 0;
int _disp14oldLength = 0;
int _disp26oldLength = 0;
int _disp31oldLength = 0;
bool _gen3I = 0;
bool _gen3O = 0;
unsigned long _gen3P = 0UL;
int _disp13oldLength = 0;
int _disp19oldLength = 0;
void setup()
{
pinMode(16, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(19, OUTPUT);
pinMode(13, OUTPUT);
disp.begin(20, 4);
pinMode(2, INPUT);
_SCT_2P=micros();
attachInterrupt( digitalPinToInterrupt (2), _SCT_2coutFunction, FALLING);
_dht1.setup(8);
_dht1LRT = millis();
_dht1Tti = millis();
}
void loop()
{if (_isNeedClearDisp1) {disp.clear(); _isNeedClearDisp1= 0;}
//Плата:1
//Наименование:Метеостанция
//Комментарии:http://radio-hobby.org
if (!(0)) {
_dispTempLength1 = (String("Метеостанция v1.01")).length();
if (_disp2oldLength > _dispTempLength1) {_isNeedClearDisp1 = 1;}
_disp2oldLength = _dispTempLength1;
disp.setCursor(0, 0);
disp.print(String("Метеостанция v1.01"));
} else {
if (_disp2oldLength > 0) {_isNeedClearDisp1 = 1; _disp2oldLength = 0;}
}
if (!(0)) {
_dispTempLength1 = (String("C")).length();
if (_disp26oldLength > _dispTempLength1) {_isNeedClearDisp1 = 1;}
_disp26oldLength = _dispTempLength1;
disp.setCursor(4, 1);
disp.print(String("C"));
} else {
if (_disp26oldLength > 0) {_isNeedClearDisp1 = 1; _disp26oldLength = 0;}
}
if (!(0)) {
_dispTempLength1 = (String("t:")).length();
if (_disp1oldLength > _dispTempLength1) {_isNeedClearDisp1 = 1;}
_disp1oldLength = _dispTempLength1;
disp.setCursor(0, 1);
disp.print(String("t:"));
} else {
if (_disp1oldLength > 0) {_isNeedClearDisp1 = 1; _disp1oldLength = 0;}
}
if(_isTimer(_dht1Tti, 1000)) {
if(_isTimer(_dht1LRT,( _dht1.getMinimumSamplingPeriod()))) {
_dht1.readSensor();
_dht1LRT = millis();
_dht1Tti = millis();
}
}
if (!(0)) {
_dispTempLength1 = ((( _floatToStringWitRaz(_dht1.humidity,0)))).length();
if (_disp17oldLength > _dispTempLength1) {_isNeedClearDisp1 = 1;}
_disp17oldLength = _dispTempLength1;
disp.setCursor(2, 2);
disp.print((( _floatToStringWitRaz(_dht1.humidity,0))));
} else {
if (_disp17oldLength > 0) {_isNeedClearDisp1 = 1; _disp17oldLength = 0;}
}
_BytesToWord_3_Out = word(0, _dht1.humidity);
if ((_BytesToWord_3_Out) >= (70)) {
_dispTempLength1 = (String("Влажно")).length();
if (_disp7oldLength > _dispTempLength1) {_isNeedClearDisp1 = 1;}
_disp7oldLength = _dispTempLength1;
disp.setCursor(6, 2);
disp.print(String("Влажно"));
} else {
if (_disp7oldLength > 0) {_isNeedClearDisp1 = 1; _disp7oldLength = 0;}
}
if (( ((_BytesToWord_3_Out) >= (40)) && ((_BytesToWord_3_Out) < (70)) )) {
_dispTempLength1 = (String("Норма")).length();
if (_disp6oldLength > _dispTempLength1) {_isNeedClearDisp1 = 1;}
_disp6oldLength = _dispTempLength1;
disp.setCursor(6, 2);
disp.print(String("Норма"));
} else {
if (_disp6oldLength > 0) {_isNeedClearDisp1 = 1; _disp6oldLength = 0;}
}
if ((_BytesToWord_3_Out) < (40)) {
_dispTempLength1 = (String("Сухо")).length();
if (_disp5oldLength > _dispTempLength1) {_isNeedClearDisp1 = 1;}
_disp5oldLength = _dispTempLength1;
disp.setCursor(6, 2);
disp.print(String("Сухо"));
} else {
if (_disp5oldLength > 0) {_isNeedClearDisp1 = 1; _disp5oldLength = 0;}
}
if (!(0)) {
_dispTempLength1 = ((( _floatToStringWitRaz(_dht1.temperature,0)))).length();
if (_disp3oldLength > _dispTempLength1) {_isNeedClearDisp1 = 1;}
_disp3oldLength = _dispTempLength1;
disp.setCursor(2, 1);
disp.print((( _floatToStringWitRaz(_dht1.temperature,0))));
} else {
if (_disp3oldLength > 0) {_isNeedClearDisp1 = 1; _disp3oldLength = 0;}
}
_BytesToWord_1_Out = word(0, _dht1.temperature);
digitalWrite(19, ( ((_BytesToWord_1_Out) >= (20)) && ((_BytesToWord_1_Out) < (25)) ));
if (( ((_BytesToWord_1_Out) >= (20)) && ((_BytesToWord_1_Out) < (25)) )) {
_dispTempLength1 = (String("Тепло")).length();
if (_disp12oldLength > _dispTempLength1) {_isNeedClearDisp1 = 1;}
_disp12oldLength = _dispTempLength1;
disp.setCursor(6, 1);
disp.print(String("Тепло"));
} else {
if (_disp12oldLength > 0) {_isNeedClearDisp1 = 1; _disp12oldLength = 0;}
}
digitalWrite(12, ( ((_BytesToWord_1_Out) >= (15)) && ((_BytesToWord_1_Out) < (20)) ));
if (( ((_BytesToWord_1_Out) >= (15)) && ((_BytesToWord_1_Out) < (20)) )) {
_dispTempLength1 = (String("Комфортно")).length();
if (_disp11oldLength > _dispTempLength1) {_isNeedClearDisp1 = 1;}
_disp11oldLength = _dispTempLength1;
disp.setCursor(6, 1);
disp.print(String("Комфортно"));
} else {
if (_disp11oldLength > 0) {_isNeedClearDisp1 = 1; _disp11oldLength = 0;}
}
if ((_BytesToWord_1_Out) >= (25)) {
_dispTempLength1 = (String("Жарко")).length();
if (_disp10oldLength > _dispTempLength1) {_isNeedClearDisp1 = 1;}
_disp10oldLength = _dispTempLength1;
disp.setCursor(6, 1);
disp.print(String("Жарко"));
} else {
if (_disp10oldLength > 0) {_isNeedClearDisp1 = 1; _disp10oldLength = 0;}
}
if ((_BytesToWord_1_Out) >= (25)) { if (! _gen2I) { _gen2I = 1; _gen2O = 1; _gen2P = millis(); } } else { _gen2I = 0 ; _gen2O= 0;}
if (_gen2I) { if ( _isTimer ( _gen2P , 500 )) { _gen2P = millis(); _gen2O = ! _gen2O;}}
digitalWrite(19, _gen2O);
digitalWrite(11, ( ((_BytesToWord_1_Out) >= (10)) && ((_BytesToWord_1_Out) < (15)) ));
if (( ((_BytesToWord_1_Out) >= (10)) && ((_BytesToWord_1_Out) < (15)) )) {
_dispTempLength1 = (String("Прохладно")).length();
if (_disp9oldLength > _dispTempLength1) {_isNeedClearDisp1 = 1;}
_disp9oldLength = _dispTempLength1;
disp.setCursor(6, 1);
disp.print(String("Прохладно"));
} else {
if (_disp9oldLength > 0) {_isNeedClearDisp1 = 1; _disp9oldLength = 0;}
}
if ((_BytesToWord_1_Out) < (10)) {
_dispTempLength1 = (String("Холодно")).length();
if (_disp8oldLength > _dispTempLength1) {_isNeedClearDisp1 = 1;}
_disp8oldLength = _dispTempLength1;
disp.setCursor(6, 1);
disp.print(String("Холодно"));
} else {
if (_disp8oldLength > 0) {_isNeedClearDisp1 = 1; _disp8oldLength = 0;}
}
if ((_BytesToWord_1_Out) < (10)) { if (! _gen1I) { _gen1I = 1; _gen1O = 1; _gen1P = millis(); } } else { _gen1I = 0 ; _gen1O= 0;}
if (_gen1I) { if ( _isTimer ( _gen1P , 500 )) { _gen1P = millis(); _gen1O = ! _gen1O;}}
digitalWrite(11, _gen1O);
if (!(0)) {
_dispTempLength1 = (String("%")).length();
if (_disp23oldLength > _dispTempLength1) {_isNeedClearDisp1 = 1;}
_disp23oldLength = _dispTempLength1;
disp.setCursor(4, 2);
disp.print(String("%"));
} else {
if (_disp23oldLength > 0) {_isNeedClearDisp1 = 1; _disp23oldLength = 0;}
}
if (!(0)) {
_dispTempLength1 = (String("h:")).length();
if (_disp4oldLength > _dispTempLength1) {_isNeedClearDisp1 = 1;}
_disp4oldLength = _dispTempLength1;
disp.setCursor(0, 2);
disp.print(String("h:"));
} else {
if (_disp4oldLength > 0) {_isNeedClearDisp1 = 1; _disp4oldLength = 0;}
}
if (!(0)) {
_dispTempLength1 = (String("м/с")).length();
if (_disp15oldLength > _dispTempLength1) {_isNeedClearDisp1 = 1;}
_disp15oldLength = _dispTempLength1;
disp.setCursor(4, 3);
disp.print(String("м/с"));
} else {
if (_disp15oldLength > 0) {_isNeedClearDisp1 = 1; _disp15oldLength = 0;}
}
if (!(0)) {
_dispTempLength1 = (String("v:")).length();
if (_disp32oldLength > _dispTempLength1) {_isNeedClearDisp1 = 1;}
_disp32oldLength = _dispTempLength1;
disp.setCursor(0, 3);
disp.print(String("v:"));
} else {
if (_disp32oldLength > 0) {_isNeedClearDisp1 = 1; _disp32oldLength = 0;}
}
if((( micros()-_SCT_2P) >60000000)||(( micros()-_SCT_2P) <0)){_SCT_2 = _SCT_2IC;_SCT_2IC=0;_SCT_2P = micros();}
if ((((3.00)*(_SCT_2))/(60)) > (10.7)) { if (! _gen5I) { _gen5I = 1; _gen5O = 1; _gen5P = millis(); } } else { _gen5I = 0 ; _gen5O= 0;}
if (_gen5I) { if ( _isTimer ( _gen5P , 250 )) { _gen5P = millis(); _gen5O = ! _gen5O;}}
digitalWrite(13, _gen5O);
if ((((3.00)*(_SCT_2))/(60)) > (24.00)) {if (! _gen4I){_gen4I = 1; _gen4O = 1; _gen4P = millis();}} else { _gen4I = 0 ; _gen4O= 0; } if (_gen4I && _gen4O) _gen4O = !( _isTimer( _gen4P , 15000 ));
if (_gen4O) { if (! _gen3I) { _gen3I = 1; _gen3O = 1; _gen3P = millis(); } } else { _gen3I = 0 ; _gen3O= 0;}
if (_gen3I) { if ( _isTimer ( _gen3P , 250 )) { _gen3P = millis(); _gen3O = ! _gen3O;}}
digitalWrite(16, _gen3O);
if ((((3.00)*(_SCT_2))/(60)) > (32.6)) {
_dispTempLength1 = (String("Ураган")).length();
if (_disp30oldLength > _dispTempLength1) {_isNeedClearDisp1 = 1;}
_disp30oldLength = _dispTempLength1;
disp.setCursor(8, 3);
disp.print(String("Ураган"));
} else {
if (_disp30oldLength > 0) {_isNeedClearDisp1 = 1; _disp30oldLength = 0;}
}
if (( ((((3.00)*(_SCT_2))/(60)) > (28.4)) && ((((3.00)*(_SCT_2))/(60)) <= (32.6)) )) {
_dispTempLength1 = (String("Буря")).length();
if (_disp29oldLength > _dispTempLength1) {_isNeedClearDisp1 = 1;}
_disp29oldLength = _dispTempLength1;
disp.setCursor(8, 3);
disp.print(String("Буря"));
} else {
if (_disp29oldLength > 0) {_isNeedClearDisp1 = 1; _disp29oldLength = 0;}
}
if (( ((((3.00)*(_SCT_2))/(60)) > (24.4)) && ((((3.00)*(_SCT_2))/(60)) <= (28.4)) )) {
_dispTempLength1 = (String("Шквал")).length();
if (_disp28oldLength > _dispTempLength1) {_isNeedClearDisp1 = 1;}
_disp28oldLength = _dispTempLength1;
disp.setCursor(8, 3);
disp.print(String("Шквал"));
} else {
if (_disp28oldLength > 0) {_isNeedClearDisp1 = 1; _disp28oldLength = 0;}
}
if (( ((((3.00)*(_SCT_2))/(60)) > (20.7)) && ((((3.00)*(_SCT_2))/(60)) <= (24.4)) )) {
_dispTempLength1 = (String("Шторм")).length();
if (_disp27oldLength > _dispTempLength1) {_isNeedClearDisp1 = 1;}
_disp27oldLength = _dispTempLength1;
disp.setCursor(8, 3);
disp.print(String("Шторм"));
} else {
if (_disp27oldLength > 0) {_isNeedClearDisp1 = 1; _disp27oldLength = 0;}
}
if (( ((((3.00)*(_SCT_2))/(60)) > (17.1)) && ((((3.00)*(_SCT_2))/(60)) <= (20.7)) )) {
_dispTempLength1 = (String("Сердитый")).length();
if (_disp25oldLength > _dispTempLength1) {_isNeedClearDisp1 = 1;}
_disp25oldLength = _dispTempLength1;
disp.setCursor(8, 3);
disp.print(String("Сердитый"));
} else {
if (_disp25oldLength > 0) {_isNeedClearDisp1 = 1; _disp25oldLength = 0;}
}
if (( ((((3.00)*(_SCT_2))/(60)) > (13.8)) && ((((3.00)*(_SCT_2))/(60)) <= (17.1)) )) {
_dispTempLength1 = (String("Крепкий")).length();
if (_disp24oldLength > _dispTempLength1) {_isNeedClearDisp1 = 1;}
_disp24oldLength = _dispTempLength1;
disp.setCursor(8, 3);
disp.print(String("Крепкий"));
} else {
if (_disp24oldLength > 0) {_isNeedClearDisp1 = 1; _disp24oldLength = 0;}
}
if (( ((((3.00)*(_SCT_2))/(60)) > (10.7)) && ((((3.00)*(_SCT_2))/(60)) <= (13.8)) )) {
_dispTempLength1 = (String("Сильный")).length();
if (_disp22oldLength > _dispTempLength1) {_isNeedClearDisp1 = 1;}
_disp22oldLength = _dispTempLength1;
disp.setCursor(8, 3);
disp.print(String("Сильный"));
} else {
if (_disp22oldLength > 0) {_isNeedClearDisp1 = 1; _disp22oldLength = 0;}
}
if (( ((((3.00)*(_SCT_2))/(60)) > (7.9)) && ((((3.00)*(_SCT_2))/(60)) <= (10.7)) )) {
_dispTempLength1 = (String("Свежий")).length();
if (_disp21oldLength > _dispTempLength1) {_isNeedClearDisp1 = 1;}
_disp21oldLength = _dispTempLength1;
disp.setCursor(8, 3);
disp.print(String("Свежий"));
} else {
if (_disp21oldLength > 0) {_isNeedClearDisp1 = 1; _disp21oldLength = 0;}
}
if (( ((((3.00)*(_SCT_2))/(60)) > (5.4)) && ((((3.00)*(_SCT_2))/(60)) <= (7.9)) )) {
_dispTempLength1 = (String("Умеренный")).length();
if (_disp20oldLength > _dispTempLength1) {_isNeedClearDisp1 = 1;}
_disp20oldLength = _dispTempLength1;
disp.setCursor(8, 3);
disp.print(String("Умеренный"));
} else {
if (_disp20oldLength > 0) {_isNeedClearDisp1 = 1; _disp20oldLength = 0;}
}
if (( ((((3.00)*(_SCT_2))/(60)) > (3.3)) && ((((3.00)*(_SCT_2))/(60)) <= (5.4)) )) {
_dispTempLength1 = (String("Слабый")).length();
if (_disp19oldLength > _dispTempLength1) {_isNeedClearDisp1 = 1;}
_disp19oldLength = _dispTempLength1;
disp.setCursor(8, 3);
disp.print(String("Слабый"));
} else {
if (_disp19oldLength > 0) {_isNeedClearDisp1 = 1; _disp19oldLength = 0;}
}
if (( ((((3.00)*(_SCT_2))/(60)) > (1.5)) && ((((3.00)*(_SCT_2))/(60)) <= (3.3)) )) {
_dispTempLength1 = (String("Лёгкий")).length();
if (_disp18oldLength > _dispTempLength1) {_isNeedClearDisp1 = 1;}
_disp18oldLength = _dispTempLength1;
disp.setCursor(8, 3);
disp.print(String("Лёгкий"));
} else {
if (_disp18oldLength > 0) {_isNeedClearDisp1 = 1; _disp18oldLength = 0;}
}
if (( ((((3.00)*(_SCT_2))/(60)) > (0.2)) && ((((3.00)*(_SCT_2))/(60)) <= (1.5)) )) {
_dispTempLength1 = (String("Тихий")).length();
if (_disp14oldLength > _dispTempLength1) {_isNeedClearDisp1 = 1;}
_disp14oldLength = _dispTempLength1;
disp.setCursor(8, 3);
disp.print(String("Тихий"));
} else {
if (_disp14oldLength > 0) {_isNeedClearDisp1 = 1; _disp14oldLength = 0;}
}
if ((((3.00)*(_SCT_2))/(60)) <= (0.2)) {
_dispTempLength1 = (String("Штиль")).length();
if (_disp13oldLength > _dispTempLength1) {_isNeedClearDisp1 = 1;}
_disp13oldLength = _dispTempLength1;
disp.setCursor(8, 3);
disp.print(String("Штиль"));
} else {
if (_disp13oldLength > 0) {_isNeedClearDisp1 = 1; _disp13oldLength = 0;}
}
if (!(0)) {
_dispTempLength1 = ((( _floatToStringWitRaz(((3.00)*(_SCT_2))/(60),0)))).length();
if (_disp31oldLength > _dispTempLength1) {_isNeedClearDisp1 = 1;}
_disp31oldLength = _dispTempLength1;
disp.setCursor(2, 3);
disp.print((( _floatToStringWitRaz(((3.00)*(_SCT_2))/(60),0))));
} else {
if (_disp31oldLength > 0) {_isNeedClearDisp1 = 1; _disp31oldLength = 0;}
}
}
String _floatToStringWitRaz(float value, int raz)
{
return String(value,raz);
}
bool _isTimer(unsigned long startTime, unsigned long period )
{
unsigned long currentTime;
currentTime = millis();
if (currentTime>= startTime) {return (currentTime>=(startTime + period));} else {return (currentTime >=(4294967295-startTime+period));}
}
void _SCT_2coutFunction()
{ _SCT_2IC++;
}
Прикреплённый файл: Meteostanciya_flp_v1.01.zip Размер: 40.23 KB; Просмотры: 289
Отправлено: 31.05.2020 3:10
|