Advertisement
pleasedontcode

Servo Control rev_01

Oct 8th, 2024
63
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 Control
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-10-08 05:50:18
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* The system shall utilize the Deneyap Servo library */
  21.     /* to control servo motors based on push button */
  22.     /* inputs from digital pin D2, ensuring responsive */
  23.     /* and accurate motor movements. */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /****** DEFINITION OF LIBRARIES *****/
  27. #include <Deneyap_Servo.h>  //https://github.com/deneyapkart/deneyap-servo-arduino-library
  28.  
  29. /****** FUNCTION PROTOTYPES *****/
  30. void setup(void);
  31. void loop(void);
  32.  
  33. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  34. const uint8_t mybutton_PushButton_PIN_D2 = 2; // Define push button pin
  35.  
  36. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  37. // Instantiate the Servo class for controlling a servo motor
  38. Servo myservo; // Create an instance of the Servo class
  39.  
  40. void setup(void)
  41. {
  42.     // Set the button pin as input with pull-up resistor
  43.     pinMode(mybutton_PushButton_PIN_D2, INPUT_PULLUP);
  44.  
  45.     // Attach the servo to pin D9 (default channel 0, freq 50, resolution 12)
  46.     myservo.attach(D9);
  47. }
  48.  
  49. void loop(void)
  50. {
  51.     // Check if the button is pressed
  52.     if (digitalRead(mybutton_PushButton_PIN_D2) == LOW) { // Button pressed (active low)
  53.         myservo.write(60); // Move the servo to 60 degrees
  54.         delay(1000); // Wait for a second
  55.         myservo.write(0); // Move the servo back to 0 degrees
  56.         delay(1000); // Wait for a second
  57.     }
  58. }
  59.  
  60. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement