Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* 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-12-24 07:19:11
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* muovere di 90° il servomotore con la pressione di */
- /* un pulsante */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <Servo.h> //https://github.com/arduino-libraries/Servo
- #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t pulsante_PushButton_PIN_D2 = 2;
- const uint8_t pulsante = 9; // Button pin
- /***** DEFINITION OF PWM OUTPUT PINS *****/
- const uint8_t servo_Servomotor_PWMSignal_PIN_D5 = 5;
- const uint8_t servoPin = 8; // Servo pin
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- uint8_t servo_Servomotor_PWMSignal_PIN_D5_rawData = 0;
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- float servo_Servomotor_PWMSignal_PWMSignal_PIN_D5_phyData = 0.0;
- // Variable to store angle
- int angolo = 0; // Current angle of the servo
- int angoloStep = 90; // Step for angle increment
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- Servo servo; // Servo instance
- EasyButton button(pulsante); // EasyButton instance
- void setup(void)
- {
- // Initialize button and servo
- pinMode(pulsante_PushButton_PIN_D2, INPUT_PULLUP);
- servo.attach(servoPin); // Attach servo to pin 8
- Serial.begin(9600); // Initialize serial communication
- button.begin(); // Initialize the button
- }
- void loop(void)
- {
- // Update button state
- button.read(); // Read button state
- // Check if the button is pressed
- if (button.isPressed()) {
- angolo += angoloStep; // Increment angle
- if (angolo > 180) { // Limit angle to 180 degrees
- angolo = 0; // Reset angle
- }
- servo.write(angolo); // Move servo to new angle
- delay(100); // Delay for servo movement
- Serial.print("Current angle: "); // Print current angle
- Serial.println(angolo);
- }
- }
- void updateOutputs()
- {
- analogWrite(servo_Servomotor_PWMSignal_PIN_D5, servo_Servomotor_PWMSignal_PIN_D5_rawData);
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement