Hi, This is my first ever project. I purchased the Arduino a few months ago but never got further than the blink example :-[ Poor I know.
Anyway I got home today from work after talking to a dude at work about a paintball sentry and it got my Arduino juices flowing.
Ive been using the examples and managed to get a Pot, Servo, Serial and LED thing going on. But I cant get my LED to light if (val > 500)
I was wondering if anyone could point me in the right direction
// Pot-Servo-Serial-LED Mod By Telly!
// :D
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int potpin = 7; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
int ledPin = 3; // LED connected to digital pin 3
void setup()
{
myservo.attach(2); // attaches the servo on pin 9 to the servo object
Serial.begin(9600); // setup serial connection
pinMode(ledPin, OUTPUT); // initialize the digital pin as an output:
}
void loop()
{
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
int analogValue = analogRead(7); // reads the value of the potentiomete
val = map(val, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
myservo.write(val); // sets the servo position according to the scaled value
Serial.println(analogValue); // sends analogValue to serial
delay(1); // waits for the servo to get there
if (val > 500)
{
digitalWrite(ledPin, HIGH);
}
}
Any "light" would be great!
Thank you all Telly.