Advertisement
Guest User

Untitled

a guest
Jun 13th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.74 KB | None | 0 0
  1. #include <Servo.h>
  2. #define MAXHOEK 90
  3. #define MINHOEK 0
  4. int LDR = 0;     //analog pin to which LDR is connected, here we set it to 0 so it means A0
  5. int LDRValue = 0;      //that’s a variable to store LDR values
  6. int light_sensitivity = 500;    //This is the approx value of light surrounding your LDR
  7. Servo myservo;
  8. int teller = 0;    //Bezit de waarde 0 als initiële waarde (servo start altijd in dezelfde positie?), is 1 als servo gedraaid is, is 0 als servo terug gedraaid is
  9.  
  10. void setup(){
  11.     Serial.begin(9600);          //start the serial monitor with 9600 buad
  12.     pinMode(10, OUTPUT);     //we mostly use 13 because there is already a built in yellow LED in arduino which shows output when 13 pin is enabled
  13.     myservo.attach(12);
  14. }
  15.  
  16. void loop(){
  17.     LDRValue = analogRead(LDR);      //reads the ldr’s value through LDR
  18.     Serial.println(LDRValue);       //prints the LDR values to serial monitor
  19.     delay(500);        //This is the speed by which LDR sends value to arduino
  20.     if (LDRValue < light_sensitivity){
  21.   digitalWrite(13, HIGH);
  22.         //maakt teller oneven als even, maakt teller even als oneven
  23.         teller++;
  24.         //maakt teller 0 als even, 1 als oneven
  25.         teller %= 2;
  26.  
  27.   if(teller){ //teller=1
  28.     //code om servo te doen draaien in een richting
  29.     myservo.write(MAXHOEK);
  30.     delay(15);
  31.   } else {    //teller=0
  32.     //code om servo terug te doen draaien
  33.     myservo.write(MINHOEK);
  34.     delay(15);
  35.   }
  36.   while(LDRValue < light_sensitivity){
  37.     LDRValue = analogRead(LDR);      //reads the ldr’s value through LDR
  38.     Serial.println(LDRValue);       //prints the LDR values to serial monitor
  39.     delay(500);        //This is the speed by which LDR sends value to arduino
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement