PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

35 行
1.1KB

  1. /* Sweep
  2. by BARRAGAN <http://barraganstudio.com>
  3. This example code is in the public domain.
  4. modified 8 Nov 2013
  5. by Scott Fitzgerald
  6. http://arduino.cc/en/Tutorial/Sweep
  7. */
  8. #include <Servo.h>
  9. Servo myservo; // create servo object to control a servo
  10. // twelve servo objects can be created on most boards
  11. int pos = 0; // variable to store the servo position
  12. void setup()
  13. {
  14. myservo.attach(9); // attaches the servo on pin 9 to the servo object
  15. }
  16. void loop()
  17. {
  18. for(pos = 0; pos <= 180; pos += 1) // goes from 0 degrees to 180 degrees
  19. { // in steps of 1 degree
  20. myservo.write(pos); // tell servo to go to position in variable 'pos'
  21. delay(15); // waits 15ms for the servo to reach the position
  22. }
  23. for(pos = 180; pos>=0; pos-=1) // goes from 180 degrees to 0 degrees
  24. {
  25. myservo.write(pos); // tell servo to go to position in variable 'pos'
  26. delay(15); // waits 15ms for the servo to reach the position
  27. }
  28. }