pleasedontcode

Motion Melody rev_119

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