A little help for a "newbie" please. I'm assisting a local artist on one of his installation pieces. I'm using an Arduino UNO board with a servo to rotate the needle of a pressure gauge (for show not real) 180 degrees and successfully accomplished this from the Arduino library "Arduino Sweep" and even figured out how to add a 5 second delay to stop the sweep at one end.
My question: Is there anyway to add 2 LEDS to my UNO to switch ON and OFF and Blink when the servo is at specific points of it sweep (by degrees)? I can do this mechanically with cam and a micro switch but thought there must be a more elegant solution in programming the UNO.
In my current Servo Sweep sketch (see below), I would like a Green LED to remain ON from 0 - 90 degrees then Turn OFF and then from 90 - 180 degrees a second Red LED to Switch ON and Blink and then reverse the ON/OFF/Blink when sweeping back during the reverse sweep. The effect is that a Green LED that is ON shows a "safe" reading between 0 - 90 degrees of the needle's sweep and then from 90 - 180 degrees the "danger" Red LED Blinks.
Is it possible to add LEDs to function like this?
My current setup is:
// Sweep
// by BARRAGAN http://barraganstudio.com
// This example code is in the public domain.
#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
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop()
{
for(pos = 0; pos < 180; 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(120); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(120); // waits 15ms for the servo to reach the position
}
delay(5000); // waits for a second
}