Arduino – Servo – CDS
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
#include <Servo.h> Servo myservo; int CDS=A0; int vars; int pos=0; int openMax=900; int openMin=700; int states=0; void setup() { myservo.attach(3); } void loop() { vars=analogRead(CDS); if (states==0 && vars > openMax) { states=1; } else if (states==1 && vars < openMin) { states=0; } if (states) { myservo.write(180); } else { myservo.write(0); } delay(15); } |