Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Servo.h>
- Servo myservo; // create servo object to control a servo
- // a maximum of eight servo objects can be created
- int pos = 0; // variable to store the servo position
- int ledPin = 4; // choose the pin for the LED
- int inputPin = 2; // choose the input pin (for PIR sensor)
- int pirState = LOW; // we start, assuming no motion detected
- int val = 0; // variable for reading the pin status
- int ledstate = 0; // the led should stay off after 1 detection
- void setup()
- {
- myservo.attach(9); // attaches the servo on pin 9 to the servo object
- pinMode(ledPin, OUTPUT); // declare LED as output
- pinMode(inputPin, INPUT); // declare sensor as input
- Serial.begin(9600);
- }
- void loop()
- {
- for(pos = 0; pos < 90; pos += 1) // goes from 0 degrees to 90 degrees
- {
- if ( digitalRead(inputPin == HIGH)) {
- digitalWrite(ledPin, LOW);
- myservo.write(pos);
- delay(30);
- }
- else {
- digitalWrite(ledPin, HIGH);
- }
- }
- for(pos = 90; pos>=1; pos -= 1) //goes from 180 to 0
- {
- if ( digitalRead(inputPin == HIGH)) {
- myservo.write(pos);
- digitalWrite(ledPin, LOW);
- delay(30);
- }
- else {
- digitalWrite(ledPin, HIGH);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement