Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
/********* Pleasedontcode.com ********** Pleasedontcode thanks you for automatic code generation! Enjoy your code! - Terms and Conditions: You have a non-exclusive, revocable, worldwide, royalty-free license for personal and commercial use. Attribution is optional; modifications are allowed, but you're responsible for code maintenance. We're not liable for any loss or damage. For full terms, please visit pleasedontcode.com/termsandconditions. - Project: "Servo Control" - Source Code NOT compiled for: Arduino Uno - Source Code created on: 2024-05-08 23:30:16 ********* Pleasedontcode.com **********/ /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* Improve user description requirement by specifying */ /* EasyButton library usage for debouncing a push */ /* button on pin D2 with INPUT_PULLUP configuration. */ /****** SYSTEM REQUIREMENT 2 *****/ /* move the servo motor of 50° if the button is */ /* pressed. */ /****** END SYSTEM REQUIREMENTS *****/ /****** DEFINITION OF LIBRARIES *****/ #include
// Include the EasyButton library for debouncing a push button #include
// Include the Servo library for controlling servo motor /****** FUNCTION PROTOTYPES *****/ void setup(void); void loop(void); void moveServo(int degrees); /***** DEFINITION OF DIGITAL INPUT PINS *****/ const uint8_t BUTTON_PIN = 2; // Define the pin for the push button (D2) /***** DEFINITION OF SERVO MOTOR PIN *****/ const uint8_t SERVO_PIN = 9; // Define the pin for the servo motor /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/ EasyButton button(BUTTON_PIN); // Create an EasyButton object for the push button Servo servoMotor; // Create a Servo object to control the servo motor void setup(void) { // Initialize the EasyButton and Servo objects button.begin(); servoMotor.attach(SERVO_PIN); // Attach the servo motor to the specified pin } void loop(void) { // Read the button state button.read(); // Move the servo motor 50 degrees if the button is pressed if (button.isPressed()) { moveServo(50); } } void moveServo(int degrees) { servoMotor.write(degrees); // Move the servo motor to the specified angle delay(15); // Delay for stability } /* END CODE */
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)