Advertisement
pleasedontcode

"Servo Setup" rev_01

Dec 15th, 2023
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: "Servo Setup"
  13.     - Source Code compiled for: Arduino Nano
  14.     - Source Code created on: 2023-12-16 05:23:31
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Turns on and off a servo motor, ON equals GREEN */
  21.     /* for a LED and https webserver POST and FETCH */
  22.     /* Boolean loop */
  23. /****** END SYSTEM REQUIREMENTS *****/
  24.  
  25. /****** DEFINITION OF LIBRARIES *****/
  26. #include <Arduino.h>
  27. #include <Servo.h>
  28. #include <ezButton.h>
  29.  
  30. /****** FUNCTION PROTOTYPES *****/
  31. void setup(void);
  32. void loop(void);
  33.  
  34. /***** DEFINITION OF PWM OUTPUT PINS *****/
  35. const uint8_t on_switch_Servomotor_PWMSignal_PIN_D3 = 3;
  36.  
  37. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  38. Servo myservo;
  39. ezButton button(4); // Initialize the ezButton object with pin 4
  40.  
  41. void setup(void)
  42. {
  43.   // put your setup code here, to run once:
  44.  
  45.   pinMode(on_switch_Servomotor_PWMSignal_PIN_D3, OUTPUT);
  46.  
  47.   // Attach the servo to the pin
  48.   myservo.attach(on_switch_Servomotor_PWMSignal_PIN_D3);
  49.  
  50.   // Set button debounce time to 50 milliseconds
  51.   button.setDebounceTime(50);
  52. }
  53.  
  54. void loop(void)
  55. {
  56.   // put your main code here, to run repeatedly:
  57.  
  58.   // Read the button state
  59.   button.loop();
  60.  
  61.   // If the button is pressed
  62.   if (button.isPressed())
  63.   {
  64.     // Move the servo to 90 degrees
  65.     myservo.write(90);
  66.     delay(500);
  67.    
  68.     // Move the servo to 0 degrees
  69.     myservo.write(0);
  70.     delay(500);
  71.   }
  72. }
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement