Hey guys.
i'm pretty familiar with the concepts of Arduino micro controller, but i've just started using one for my final year of high school in Systems Engineering.
the project i'm making is a replica of the Team fortress 2 Level 2 Sentry gun.
i know some of the basics and I've been trying to write some simple code for the Arduino Uno SMD Rev3 on the Arduino 1.0.5 that would allow me to have a servo moving from 0-125 degrees and back on loop until a PIR sensor detects motion and causes the servo stop moving for 5 seconds and then resume back to the Servo movement loop.
I've tried to see if other people have been doing things similar but all i can find are people who make the servo move after motion is detected.
I've also looked into Interrupts or ISR (interrupt service routine) but they're a little complex for me at the moment and i'm wondering if this could be done
i have my unfinished and possibly completely whack code here
int Pir = 2; //Pir sensor is Pin 2
#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
// Pin 2 has an Motion sensor connected
// give it a name:
void setup() { // the setup routine runs once when you press reset
pinMode(PIR, INPUT); // initialize the digital pin as an output.
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop() // the loop routine runs over and over again forever
{
for(pos = 0; pos < 120; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(25); // waits 25ms for the servo to reach the position
}
for(pos = 120; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(25); // waits 25ms for the servo to reach the position
}
{
digitalRead(Pir); // Reads if PIR input is high or low
if (Pir, HIGH); // If it Reads high
digitalWrite (myservo, LOW); //
else
for(pos = 0; pos < 120; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(25); // waits 25ms for the servo to reach the position
}
for(pos = 120; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(25); // waits 25ms for the servo to reach the position
}
}
}
}
I know this code probably doesn't make much sense but if you can see what i'm trying to do that's great.
I was trying to make the servo move and then when motion was sensed to stop moving the servo.
if anyone could help me that'd be greatly appreciated
Thank you for your time
Tryndus