Помогите с кодом.

StaniskavMiG
Offline
Зарегистрирован: 25.03.2017

Сильно не пинайте) пока постигаю.

#include <TimeAlarms.h> 
#include <DHT.h>    
     
#define DHTPIN 12        
#define DHTTYPE DHT22 
#define S_ON 0 
#define S_OFF 1 
#define NO_ACTION      0   
#define IN_RANGE       1 
#define OUT_RANGE      2 

typedef struct RunCondition {
      int socketPin; 
      float tempBegin; 
      float tempEnd; 
      int tempMode;    
      float humBegin;
      float humEnd;   
      int humMode;    
};

#define NUM_SOCKETS 3 
RunCondition sockets[NUM_SOCKETS] = {
{
2,       
26.0,    
100.0, 
IN_RANGE,
0.0,
0.0,
NO_ACTION 
},
{
3,       
20.0,    
IN_RANGE, 
0.0,
0.0,
NO_ACTION 
},
{
4,       
20.0,    
100.0, 
IN_RANGE, 
0.0,     
70.0,    
IN_RANGE 
}
};
int socketStatus[NUM_SOCKETS]; // S_OFF - выключено, S_ON - включено.

DHT dht(DHTPIN, DHTTYPE); 

float temp = 0;
float hum = 0;
int displayMode = 0; 
void setSockets() {

for (int i = 0; i < NUM_SOCKETS; i++) {

digitalWrite(sockets[i].socketPin, socketStatus[i]);
}
}
void printSensors() {

Serial.print("[ >> ] Temperature: "); Serial.print(temp); Serial.print(" C;\tHumidity: "); Serial.print(hum); Serial.println("%");
}
void setup() {

Serial.begin(115200); 
Serial.println("[ ++ ] v.1.1.d");
dht.begin(); 
for (int i = 0; i < NUM_SOCKETS; i++) {
socketStatus[i] = S_OFF; 
pinMode(sockets[i].socketPin, OUTPUT); 
}
setSockets(); 
Alarm.timerRepeat(5, printSensors); 
displayInfo();
}
void displayInfo() {

Alarm.delay(1000); 
temp = dht.readTemperature(); 
hum = dht.readHumidity(); 

if (isnan(temp) || isnan(hum)) {

for (int i = 0; i < NUM_SOCKETS; i++) socketStatus[i] = S_OFF;
setSockets();
Serial.println("[FAIL] Can't read sensor data! Turn everithing OFF!");
return;
}

for (int s = 0; s < NUM_SOCKETS; s++) {

int tempStatus = S_OFF;
switch (sockets[s].tempMode) {
         case NO_ACTION:
         tempStatus = S_ON;
         break;
         case IN_RANGE:
         if ((temp >= sockets[s].tempBegin) && (temp <= sockets[s].tempEnd)) tempStatus = S_ON;
         break;
         case OUT_RANGE:
         if ((temp <= sockets[s].tempBegin) || (temp >= sockets[s].tempEnd)) tempStatus = S_ON;
         break; 
}

int humStatus = S_OFF;
switch (sockets[s].humMode) {
         case NO_ACTION:
         humStatus = S_ON;
         break;
         case IN_RANGE:
         if ((hum >= sockets[s].humBegin) && (hum <= sockets[s].humEnd)) humStatus = S_ON;
         break;
         case OUT_RANGE:
         if ((hum <= sockets[s].humBegin) || (hum >= sockets[s].humEnd)) humStatus = S_ON;
         break; 
}

int newStatus = S_OFF;
if ((tempStatus == S_ON) && (humStatus == S_ON)) newStatus = S_ON;

if (socketStatus[s] != newStatus) {
         
         Serial.print("[ OK ] Socket #"); Serial.print(s); Serial.print(" status has changed to "); Serial.println(newStatus);
         socketStatus[s] = newStatus;
}

setSockets();
}
}

 

 

StaniskavMiG
Offline
Зарегистрирован: 25.03.2017

при проверке выдает ошибку (warning: 'typedef' was ignored in this declaration)

Клапауций 112
Клапауций 112 аватар
Offline
Зарегистрирован: 01.03.2017

maxresdefault.jpg

qwone
qwone аватар
Offline
Зарегистрирован: 03.07.2016

Извините, но я не понял зачем такая пляска(смешение) в коде. 

OlegK
OlegK аватар
Offline
Зарегистрирован: 26.11.2014

StaniskavMiG пишет:
при проверке выдает ошибку (warning: 'typedef' was ignored in this declaration)

Где вы увидели ошибку? ворнинг - это предупреждение. Уберите typedef и ворнинг пропадёт...