Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. #define pin 10 // data pin to control servo
  2.  
  3. // pulse width (in microseconds)
  4. int pulsewidth = 2500; // 4 Hz
  5.  
  6. // wave period in microseconds
  7. int period = 20000; // 50 Hz
  8.  
  9. void setup() {
  10. pinMode(pin, OUTPUT);
  11. }
  12.  
  13. void loop() {
  14.  
  15. // turn pulse on for pulsewidth duration
  16. digitalWrite(pin, HIGH);
  17. delayMicroseconds(pulsewidth);
  18.  
  19. // turn pulse off
  20. digitalWrite(pin, LOW);
  21. delayMicroseconds(period - pulsewidth);
  22.  
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement