Sensore di movimento & servomotore & led*2
Codice:
#include <Servo.h>
Servo primoservo;
int poson = 1 ;
int posoff = 100 ;
int pirPin = 7;
int ledPin = 13;
int led2Pin=12;
void setup() {
pinMode(pirPin, INPUT);
pinMode(ledPin, OUTPUT);
pinMode(led2Pin,OUTPUT);
digitalWrite(pirPin, LOW);
primoservo.attach(9);
}
void loop() {
if( digitalRead(pirPin) == HIGH ) {
digitalWrite(ledPin, HIGH);
digitalWrite(led2Pin,LOW);
primoservo.write(50);
delay(2000);
primoservo.write(90);
digitalWrite(ledPin, LOW);
digitalWrite(led2Pin,HIGH);
delay(2000);
digitalWrite(led2Pin,LOW);
}
}
Nessun commento:
Posta un commento