Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Turret code for the Digispark / Attiny85 microcontroller
- //This code is based on the example "Sweep" from SoftRcPulseOut library, modify at will!
- #include <SoftRcPulseOut.h>
- SoftRcPulseOut myservo;
- #define SERVO_PIN 0 // assigns signal pin for servo (pin 0)
- #define NOW 1
- int spd = 40; // time between each degree of angle, higher time means slower speed
- int i = 0;
- int k = 0;
- int ang = 90;
- void setup()
- {
- myservo.attach(SERVO_PIN); // attaches the servo on pin defined by SERVO_PIN to the servo object
- myservo.write(ang);
- delay(1000);
- SoftRcPulseOut::refresh(NOW); //
- ang = 45;
- }
- void loop()
- {
- for(i = 0; i < 90; i++) //sweeps to one side 90 degrees
- {
- myservo.write(ang+i);
- delay(spd);
- SoftRcPulseOut::refresh(NOW);
- }
- delay(1000);
- for(k = 89; k>-1; k--) //sweeps to the other side 90 degrees
- {
- myservo.write(ang+k);
- delay(spd);
- SoftRcPulseOut::refresh(NOW);
- }
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement