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: Motion Melody
- - Source Code compiled for: Arduino Uno
- - Source Code created on: 2025-08-14 23:51:20
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* if vibrationSignal == 1, so transform activateSong */
- /* in output and activate it LOW for 500ms and then */
- /* retransform activateSong in digital input with */
- /* pull up again. Then move servo to 180°, maintain */
- /* it for 30 seconds and then go back again to 0°. */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <Servo.h> //https://github.com/arduino-libraries/Servo
- // Create Servo object
- Servo myservo;
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t vibrationSignal_PIN_D2 = 2;
- const uint8_t activateSong_PIN_D4 = 4;
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t myActiveBuzzer_ActiveBuzzer_output_PIN_D5 = 5;
- /***** DEFINITION OF PWM OUTPUT PINS *****/
- const uint8_t myServo_Servomotor_PWMSignal_PIN_D3 = 3;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(vibrationSignal_PIN_D2, INPUT);
- pinMode(activateSong_PIN_D4, INPUT_PULLUP);
- pinMode(myActiveBuzzer_ActiveBuzzer_output_PIN_D5, OUTPUT);
- // Attach servo to PWM pin
- myservo.attach(myServo_Servomotor_PWMSignal_PIN_D3);
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- if (digitalRead(vibrationSignal_PIN_D2) == HIGH)
- {
- // Activate song by temporarily driving activation pin to LOW for 500ms
- // Step 1: switch activation pin to OUTPUT and drive LOW
- pinMode(activateSong_PIN_D4, OUTPUT);
- digitalWrite(activateSong_PIN_D4, LOW);
- delay(500);
- // Step 2: revert to input with pull-up
- pinMode(activateSong_PIN_D4, INPUT_PULLUP);
- // Move servo to 180° and hold for 30 seconds
- myservo.write(180);
- delay(30000);
- // Return servo to 0°
- myservo.write(0);
- // Small pause to avoid retriggering immediately
- delay(100);
- }
- // Small delay to avoid saturation
- delay(10);
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment