Advertisement
Guest User

Code double slit experiment

a guest
Jun 26th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Adjusted from Sweep and Knob examples by Stijn van der Lippe
  2.  
  3. #include <Servo.h>
  4.  
  5. Servo myservo;                        // create servo object to control a servo
  6.                                       // twelve servo objects can be created on most boards
  7.  
  8. int pos = 100;                        // variable to store the servo position, starts at 100 degrees
  9. int potpin = A0;                       // analog pin used to connect the potentiometer
  10. int wait;                             // variable to read the value from the analog pin
  11.  
  12. void setup() {
  13.   myservo.attach(9);                  // attaches the servo on pin 9 to the servo object
  14. }
  15.  
  16. void loop() {
  17.   wait = analogRead(potpin);          // reads the value of the potentiometer (value between 0 and 1023)
  18.   wait = map(wait, 0, 1023, 150, 500);// scale it to use it with the delay (value between 150ms and 500ms)
  19.   myservo.write(pos);                 // tell servo to go to position in variable 'pos'
  20.   delay(wait);                        // waits a certain a amount of ms stored in variable 'wait' for the servo to reach the position
  21.   pos += 80;                          // set position variable forward 80 degrees
  22.   myservo.write(pos);                 // tell servo to go to position in variable 'pos'
  23.   delay(wait);                        // waits a certain a amount of ms stored in variable 'wait' for the servo to reach the position
  24.   pos -= 80;                          // set position variable back 80 degrees
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement