I'm trying to make a something with one flora, two TSL2561 light sensors and two micro servos. Each light sensor pairs up with a single micro servo, so based on the brightness of surroundings, each servo rotates to the different angle.
Specifically, the light sensor 1 controls micro servo 1 based on its light input, and light sensor 2 controls servo 2 in the same way. I've succeeded in making it happened, but still have some problems that I can't solve. Here below are the part of the code that I wrote and further questions.
Code: Select all
void loop(void)
{
// sensor 1 + servo 1 Event
sensors_event_t event;
tsl1.getEvent(&event);
if (event.light)
{
Serial.print(event.light); Serial.println(" lux1");
}
else
{
Serial.println("Sensor overload");
}
if (event.light > 50) {
servo1.slowmove(150, servo_speed);
delay(2000);
}
if (event.light > 100) {
servo1.slowmove(180, servo_speed);
delay(2000);
}
else {
servo1.write(servo_default);
}
// sensor 2 + servo2 Event
tsl2.getEvent(&event);
if (event.light)
{
Serial.print(event.light); Serial.println(" lux2");
}
else
{
Serial.println("Sensor overload");
}
delay(250);
if (event.light > 50) {
servo2.slowmove(150, servo_speed);
delay(2000);
}
if (event.light > 100) {
servo2.slowmove(180, servo_speed);
delay(2000);
}
else {
servo2.write(servo_default);
}
}
2. How can I pause servo on the most current position when the sensor maintains the same input?
I haven't figure out how to solve this problem for a long time, but I really want to know the solution. Even if I apply a quite long delay, servo continues to go back to the default position right after reaching to certain position. So, servo's movement looks really jumpy and unstable. I want to hold servo's angle if the input from the sensor doesn't change.