Sketch for remote shutter

From XPUB & Lens-Based wiki
Revision as of 13:08, 7 December 2017 by Sal Miranda (talk | contribs) (Created page with "<source lang="java"> #include <Servo.h> Servo myservo; int val; //variable for sensor value's int thresh = 629; //threshold LDR int pos = 0; //rest position vo...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
#include <Servo.h>

Servo myservo;
int val;         //variable for sensor value's
int thresh = 629;      //threshold LDR
int pos = 0;  //rest position

void setup()
{
  myservo.attach(8);  // attaches the servo on pin 9 to the servo object
  Serial.begin(9600);
  
}

void loop()
{

val = analogRead(0);
 Serial.println(val);
myservo.write(0); //write rest position

if (val > thresh){                //compare threshold to sensor value
myservo.write(30);                //move servo to position given by the amount of light 
delay(1000);
myservo.write(0);
delay(1000);
myservo.detach();

}

}