wanek
April 20, 2018, 9:54pm
16
Shadeyman:
int relay1 = 14;
int relay2 = 12;
int relay3 = 13;
int relay4 = 15;
int relay5 = 2;
int relay6 = 0;
int relay7 = 4;
int relay8 = 5;
int relayVButton1 = 0;
int relayVButton2 = 0;
int relayVButton3 = 0;
int relayVButton4 = 0;
int relayVButton5 = 0;
int relayVButton6 = 0;
int relayVButton7 = 0;
int relayVButton8 = 0;
boolean relayState1 = 1;
boolean relayState2 = 1;
boolean relayState3 = 1;
boolean relayState4 = 1;
boolean relayState5 = 1;
boolean relayState6 = 1;
boolean relayState7 = 1;
boolean relayState8 = 1;
man, try to use arrays + for cycles for tasks like this! the above solution is soo lame and not scalable. think about it, what if next time you need to use 500 relays / anythings? you would manually declare 500 variables? no…
study this topic:
not the answer you’re looking for, but for such cases when “classes” would be needed, i use arrays instead.
lets take your example, with the room, and say each room has the following members:
temperature actual
temperature target
heater relay gpio pin
i would create 3 arrays with the max number of the rooms (let’s say we have 10 rooms), with the needed types:
float roomActualTemp[ROOMS];
float roomTargetTemp[ROOMS];
byte roomHeater[ROOMS]; // output pins for heater relays
because all…
and arrays in general:
The Arduino programming language Reference, organized into Functions, Variable and Constant, and Structure keywords.
1 Like