SHARE
TWEET

Laser Turret testing code

w0lfiesmith Nov 12th, 2013 1,613 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Servo.h>
  2.  
  3. Servo vert,hori;  // create servo object to control a servo
  4.                 // a maximum of eight servo objects can be created
  5.  
  6. int pos = 0;    // variable to store the servo position
  7. int laser = 12;
  8. int buzzer = 11;
  9.  
  10. void setup()
  11. {
  12.   hori.attach(9);
  13.   vert.attach(10);  // attaches the servo on pin 9 to the servo object
  14.   pinMode(laser,OUTPUT);
  15.   pinMode(buzzer,OUTPUT);
  16. }
  17.  
  18.  
  19. void loop()
  20. {
  21.   digitalWrite(laser,HIGH);
  22.   analogWrite(buzzer,1);
  23.   for(pos = 0; pos < 180; pos += 10)  // goes from 0 degrees to 180 degrees
  24.   {                                  // in steps of 1 degree
  25.     vert.write(pos);
  26.     hori.write(pos);    // tell servo to go to position in variable 'pos'
  27.     delay(100);                       // waits 15ms for the servo to reach the position
  28.   }
  29.   digitalWrite(laser,LOW);
  30.   analogWrite(buzzer, 0);
  31.   for(pos = 180; pos>=1; pos-=10)     // goes from 180 degrees to 0 degrees
  32.   {                                
  33.     vert.write(pos);              // tell servo to go to position in variable 'pos'
  34.     hori.write(pos);
  35.     delay(100);                       // waits 15ms for the servo to reach the position
  36.   }
  37. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top