Skip to content

Instantly share code, notes, and snippets.

@martinius96
Last active September 18, 2022 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martinius96/37b9512934daa4591729e506307e3437 to your computer and use it in GitHub Desktop.
Save martinius96/37b9512934daa4591729e506307e3437 to your computer and use it in GitHub Desktop.
Časová kontrola vodárne - dárlingu
//Autor: Martin Chlebovec (martinius96@gmail.com)
//Časová kontrola vodárne - dárlingu
#include <avr\wdt.h>
const int buttonPin = 2; //kontakt, na ktory sa privedie +5V
const int instantResetPin = 3; //kontakt, na ktory sa privedie +5V
unsigned long lastDebounceTime = 0; //premenna pre cas millis()
int rezim = 0; //rezim systemu
int pocet_merani = 0; //pocet merani (cyklov), rataju sa do 2 minut --> 120 sekund
const int zelenaLED = 6; //D pin zelenej LED
const int cervenaLED = 7; //D pin cervenej LED
const int modraLED = 9; //D pin cervenej LED
const int vystup = 8; //D pin pre rele
int reading;
int reading2;
int reading3;
void setup() {
wdt_enable(WDTO_500MS );
wdt_reset();
pinMode(buttonPin, INPUT);
pinMode(instantResetPin, INPUT);
pinMode(zelenaLED, OUTPUT);
pinMode(cervenaLED, OUTPUT);
pinMode(vystup, OUTPUT);
digitalWrite(vystup, HIGH);
digitalWrite(zelenaLED, LOW);
digitalWrite(cervenaLED, LOW);
digitalWrite(modraLED, LOW);
}
void loop() {
wdt_reset();
reading3 = digitalRead(instantResetPin);
if (reading3 == HIGH) {
rezim = 2;
digitalWrite(modraLED, HIGH);
digitalWrite(cervenaLED, LOW);
digitalWrite(zelenaLED, LOW);
digitalWrite(vystup, HIGH);
}
switch (rezim) {
case 0:
reading = digitalRead(buttonPin);
if (reading == HIGH) {
lastDebounceTime = millis();
rezim = 1;
digitalWrite(zelenaLED, HIGH);
digitalWrite(vystup, LOW);
}
break;
case 1:
if (millis() - lastDebounceTime >= 1000) {
lastDebounceTime = millis();
reading2 = digitalRead(buttonPin);
if (reading2 == HIGH) {
pocet_merani++;
} else {
rezim = 0;
pocet_merani = 0;
digitalWrite(zelenaLED, LOW);
digitalWrite(vystup, HIGH);
}
if (pocet_merani > 120) {
rezim = 2;
digitalWrite(cervenaLED, HIGH);
digitalWrite(zelenaLED, LOW);
digitalWrite(vystup, HIGH);
}
}
break;
default:
// NUTNY RESTART ARDUINA NATVRDO CEZ RESET
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment