Guest User

Untitled

a guest
Aug 20th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. //ボタンを押すと、モーターが回るプログラム
  2.  
  3. #include <Servo.h>
  4.  
  5.  
  6. #define motorPin 3
  7. #define buttonPin 12
  8.  
  9. int buttonState = 0;
  10.  
  11. Servo myservo;
  12.  
  13. void setup() {
  14. myservo.attach(motorPin,700,2300);
  15.  
  16. pinMode(buttonPin, INPUT);
  17. Serial.begin(9600);
  18.  
  19. }
  20.  
  21. void loop() {
  22. if (digitalRead(buttonPin) == HIGH){
  23. buttonState++;
  24.  
  25. if(buttonState >1) buttonState = 0;
  26. delay(300);
  27.  
  28. }
  29.  
  30. if (buttonState == 1) {
  31. Serial.println("Switch ON");
  32.  
  33. //時計回り(when 1450~700 µsec) 逆時計回り(when 1550~2300 µsec) 1500に近い方が回転がおそくなる
  34. myservo.write(1400); //時計回り
  35. delay(100);
  36.  
  37. } else {
  38.  
  39. myservo.write(1500); //stop
  40. delay(100);
  41.  
  42. }
  43.  
  44. }
Add Comment
Please, Sign In to add comment