Automatic Sunglasses


introduction





C++
#include <SoftwareServo1.h> /* use SoftwareServo Library (Allows for ATTINY 85 usage integration as well) */
SoftwareServo1 myServo; /* Name the servo "myServo" */
int servoPin = 0; /* Create variable for Servo on Pin 0 */
int ldr = A1;
int value = 0;
int i;/* Create variable for counting refreshes */
void setup()
{
myServo.attach(servoPin); /* Attach servo object to desired output pin */
/* The best minimum & maximum pulse widths will depend on the brand & type
of servo used. These settings work well with our Towerpro microservos. */
myServo.setMinimumPulse(496); /* set minimum pulse width */
myServo.setMaximumPulse(2245); /* set maximum pulse width */
}
void loop()
{
value = analogRead(ldr); // Read the sensor value and check if the value is above or below our desired threshold
delay(100);
if(value<100)
{
myServo.write(155);
for (i = 1; i < 30; i++)
{ SoftwareServo1::refresh(); /* Refresh servo after moving */
delay(50);
}
}
else
{
myServo.write(80);
for (i = 1; i < 30; i++)
{ SoftwareServo1::refresh(); /* Refresh servo after moving */
delay(50);
}
}
}
Produced @ UTSA Robotics & Automation Laboratory