Created
January 2, 2018 22:25
-
-
Save renaud/00108f5309f3532e50e9de8f1d7af82e to your computer and use it in GitHub Desktop.
Arduino beerfiller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// dec 2017 | |
// max 2 open at the same time | |
// oct 2017, works well | |
// compact for-loop | |
// same threshold everywhere | |
// improved debugging output | |
const int STOP_BUTTON = 12; | |
const int START_BUTTON = 2; | |
const int ALL_OFF_LED = 1; | |
const int COMMANDE_VANNE[6] = {3, 5, 6, 9, 10, 11}; // PWM's | |
const int CONTACTEUR_VANNE[6] = {0, 1, 2, 3, 4, 5}; // Analog In | |
const int THRESHOLD[6] = {200, 200, 200, 200, 200, 200}; | |
int valeurVanne[6] = {0, 0, 0, 0, 0, 0}; // from analogRead | |
int stateVanne[6] = {0, 0, 0, 0, 0, 0}; // on/off | |
const int MAX_SIMULT_OPEN = 2; | |
void setup() { | |
Serial.begin(9600); | |
Serial.println("setup..."); | |
for (int i = 0; i <= 5; i++) { | |
pinMode(COMMANDE_VANNE[i], OUTPUT); | |
} | |
pinMode(STOP_BUTTON, INPUT_PULLUP); | |
pinMode(START_BUTTON, INPUT_PULLUP); | |
pinMode(ALL_OFF_LED, OUTPUT); | |
} | |
void loop() { | |
if (digitalRead(START_BUTTON) == LOW) { | |
for (int i = 0; i <= 5; i++) { | |
stateVanne[i] = 1;// = {1, 1, 1, 1, 1, 1}; | |
} | |
} | |
int simult_open = 0; | |
for (int i = 0; i <= 5; i++) { | |
valeurVanne[i] = analogRead(CONTACTEUR_VANNE[i]); | |
Serial.print(valeurVanne[i]); | |
Serial.print("\t"); | |
if ( (stateVanne[i] == 1) && simult_open < MAX_SIMULT_OPEN) { //((valeurVanne[i]) < THRESHOLD[i]) && | |
digitalWrite(COMMANDE_VANNE[i], HIGH); | |
simult_open += 1; | |
Serial.print("*ON"); | |
} | |
if ((digitalRead(STOP_BUTTON) == LOW) || (valeurVanne[i] >= THRESHOLD[i] && stateVanne[i] == 1)) { | |
digitalWrite(COMMANDE_VANNE[i], LOW); | |
Serial.print("off"); | |
simult_open -= 1; | |
stateVanne[i] = 0; // off | |
} | |
Serial.print("\t"); | |
} | |
if (simult_open == 6) { | |
Serial.print("ALL_OFF"); | |
digitalWrite(ALL_OFF_LED, HIGH); | |
} else { | |
digitalWrite(ALL_OFF_LED, LOW); | |
} | |
Serial.println(); | |
delay(100); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment