pleasedontcode

Servo Activation rev_118

Aug 14th, 2025
370
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 Activation
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2025-08-14 23:47:45
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* if vibrationSignal == 1, so transform activateSong */
  21.     /* in output and activate it LOW for 500ms and then */
  22.     /* retransform activateSong in digital input with */
  23.     /* pull up again. Then move servo to 180°, maintain */
  24.     /* it for 30 seconds and then go back again to 0°. */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27.  
  28. /* START CODE */
  29.  
  30. /****** DEFINITION OF LIBRARIES *****/
  31. #include <Servo.h>  //https://github.com/arduino-libraries/Servo
  32.  
  33. // Create Servo object
  34. Servo myservo;
  35.  
  36. /****** FUNCTION PROTOTYPES *****/
  37. void setup(void);
  38. void loop(void);
  39.  
  40. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  41. const uint8_t vibrationSignal_PIN_D2        = 2;
  42. const uint8_t activateSong_PIN_D4       = 4;
  43.  
  44. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  45. const uint8_t myActiveBuzzer_ActiveBuzzer_output_PIN_D5     = 5;
  46.  
  47. /***** DEFINITION OF PWM OUTPUT PINS *****/
  48. const uint8_t myServo_Servomotor_PWMSignal_PIN_D3       = 3;
  49.  
  50. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  51.  
  52. void setup(void)
  53. {
  54.     // put your setup code here, to run once:
  55.  
  56.     pinMode(vibrationSignal_PIN_D2, INPUT);
  57.     pinMode(activateSong_PIN_D4,    INPUT_PULLUP);
  58.  
  59.     pinMode(myActiveBuzzer_ActiveBuzzer_output_PIN_D5,   OUTPUT);
  60.     // Attach servo to PWM pin
  61.     myservo.attach(myServo_Servomotor_PWMSignal_PIN_D3);
  62.  
  63. }
  64.  
  65.  
  66. void loop(void)
  67. {
  68.     // put your main code here, to run repeatedly:
  69.  
  70.     if (digitalRead(vibrationSignal_PIN_D2) == HIGH)
  71.     {
  72.         // Activate song by temporarily driving activation pin to LOW for 500ms
  73.         // Step 1: switch activation pin to OUTPUT and drive LOW
  74.         pinMode(activateSong_PIN_D4, OUTPUT);
  75.         digitalWrite(activateSong_PIN_D4, LOW);
  76.         delay(500);
  77.         // Step 2: revert to input with pull-up
  78.         pinMode(activateSong_PIN_D4, INPUT_PULLUP);
  79.  
  80.         // Move servo to 180° and hold for 30 seconds
  81.         myservo.write(180);
  82.         delay(30000);
  83.  
  84.         // Return servo to 0°
  85.         myservo.write(0);
  86.         // Small pause to avoid retriggering immediately
  87.         delay(100);
  88.     }
  89.  
  90.     // Small delay to avoid saturation
  91.     delay(10);
  92. }
  93.  
  94. /* END CODE */
  95.  
Advertisement
Add Comment
Please, Sign In to add comment