Advertisement
Guest User

Rust auto turret swipe Digispark/Attiny85

a guest
Mar 5th, 2021
1,968
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1.  
  2. // Turret code for the Digispark / Attiny85 microcontroller
  3. //This code is based on the example "Sweep" from SoftRcPulseOut library, modify at will!
  4.  
  5. #include <SoftRcPulseOut.h>
  6. SoftRcPulseOut myservo;
  7. #define SERVO_PIN 0 // assigns signal pin for servo (pin 0)
  8.  
  9. #define NOW 1
  10. int spd = 40; // time between each degree of angle, higher time means slower speed
  11. int i = 0;
  12. int k = 0;
  13. int ang = 90;
  14.  
  15.  
  16.  
  17. void setup()
  18. {
  19. myservo.attach(SERVO_PIN); // attaches the servo on pin defined by SERVO_PIN to the servo object
  20. myservo.write(ang);
  21. delay(1000);
  22. SoftRcPulseOut::refresh(NOW); //
  23. ang = 45;
  24. }
  25.  
  26.  
  27. void loop()
  28. {
  29. for(i = 0; i < 90; i++) //sweeps to one side 90 degrees
  30. {
  31. myservo.write(ang+i);
  32. delay(spd);
  33. SoftRcPulseOut::refresh(NOW);
  34. }
  35. delay(1000);
  36.  
  37. for(k = 89; k>-1; k--) //sweeps to the other side 90 degrees
  38. {
  39. myservo.write(ang+k);
  40. delay(spd);
  41. SoftRcPulseOut::refresh(NOW);
  42. }
  43. delay(1000);
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement