// Aubergine electrique farcie aux de puces 1.0 // Aubergine Plug is a plug to switch on and off objects that are plug in it. #define SWITCH 5 typedef struct type_plug { unsigned int switch_pin; unsigned int pot_pin; unsigned int triac_pin; boolean switch_val; unsigned int pot_val; unsigned long currentMillis; unsigned long previousMillis; unsigned long interval; boolean triacState; unsigned int master; }; unsigned int switch_sum = 0; unsigned long masterCurrentMillis = 0; unsigned long masterPreviousMillis = 0; unsigned long masterTempo = 2000; boolean masterTriacState = 0; type_plug plug[SWITCH] = { {2, 0, 7, 0, 0, 0, 0, 0, 0, 0}, {3, 1, 8, 0, 0, 0, 0, 0, 0, 0}, {4, 2, 9, 0, 0, 0, 0, 0, 0, 0}, {5, 3, 10, 0, 0, 0, 0, 0, 0, 0}, {6, 4, 11, 0, 0, 0, 0, 0, 0, 0}, }; boolean DEBUG_pot = false; // print pot val to the serial port boolean DEBUG_switch = false; // print switch val to the serial port boolean DEBUG_triac = false; // print triac val to the serial port void setup(){ if(DEBUG_pot || DEBUG_switch || DEBUG_triac) Serial.begin(9600); // set the boad rate of the communication ligne for(int i=0; i= plug[i].interval){ // if time is over interval if(plug[i].triacState == 0){ plug[i].triacState = 1; } else { plug[i].triacState = 0; } digitalWrite(plug[i].triac_pin, plug[i].triacState); plug[i].previousMillis = plug[i].currentMillis; // init time plug counter } if(DEBUG_switch){ Serial.print(plug[i].switch_pin, DEC), Serial.print("\t"); Serial.print(plug[i].switch_val, DEC), Serial.print("\t"); Serial.print(switch_sum, DEC), Serial.print("\t"); Serial.print(plug[i].master, DEC), Serial.print("\t"); Serial.print(masterTempo, DEC); } if(DEBUG_pot){ Serial.print(plug[i].switch_pin, DEC), Serial.print("\t"); Serial.print(plug[i].currentMillis, DEC), Serial.print("\t"); Serial.print(plug[i].interval, DEC), Serial.print("\t"); Serial.print(plug[i].pot_val); } if(DEBUG_triac){ Serial.print(plug[i].currentMillis, DEC), Serial.print("\t"); Serial.print(plug[i].previousMillis, DEC), Serial.print("\t"); Serial.print(plug[i].interval, DEC), Serial.print("\t"); Serial.print(plug[i].triacState, DEC); } if(DEBUG_pot || DEBUG_switch || DEBUG_triac) Serial.println(); } }