
Kód: Vybrat vše
#include <Servo.h> //kniznica pre servo
Servo myservo; //objekt serva
#define Relay1 4
unsigned long predchadzajucimillis = 0; // will store last time LED was updated
unsigned long previousMillis = 0; // will store last time LED was updated
const long interval5s = 5000; // interval at which to blink (milliseconds)
void setup() //do these things once
{
Serial.begin(9600); //set data transmission rate to communicate with computer
pinMode(8,INPUT);
pinMode(Relay1,OUTPUT);
pinMode(Relay1,HIGH);
myservo.attach(9); //servo na pin 9
myservo.write(0); //uvodny uhol
}
void loop()
{
if (digitalRead(8) == HIGH){
Serial.println("Otvorene"); //print the word "open"
unsigned long aktualmillis = millis();
if (aktualmillis - predchadzajucimillis >= interval5s) {
predchadzajucimillis = aktualmillis;
Serial.println("Podmienka splnena");
myservo.write(180); //otherwise, servo position is 150 degrees
Serial.println("Servo 180°");
Serial.println(""); //print nothing, go to next line
Serial.println("closed"); //print the word "closed"
Serial.print("waiting 30 second"); //print "waiting 5 seconds"
Serial.println(""); //print nothing, go to next line
digitalWrite(Relay1,HIGH);
}