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: Vibration Servo
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2024-07-25 00:26:23
- ********* 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 *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <Servo.h> //https://github.com/arduino-libraries/Servo
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void updateOutputs(void);
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t vibrationSignal_PIN_D2 = 2;
- const uint8_t activateSong_PIN_D4 = 4;
- /***** DEFINITION OF PWM OUTPUT PINS *****/
- const uint8_t myServo_Servomotor_PWMSignal_PIN_D3 = 3;
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- /***** used to store raw data *****/
- uint8_t myServo_Servomotor_PWMSignal_PIN_D3_rawData = 0;
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- /***** used to store data after characteristic curve transformation *****/
- float myServo_Servomotor_PWMSignal_PIN_D3_phyData = 0.0;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- // Create an instance of the Servo class
- Servo myservo; // This initializes the Servo object
- void setup(void)
- {
- // Attach the Servo control to the PWM output pin
- myservo.attach(myServo_Servomotor_PWMSignal_PIN_D3); // Attach the servo to pin D3
- pinMode(vibrationSignal_PIN_D2, INPUT);
- pinMode(activateSong_PIN_D4, INPUT_PULLUP);
- pinMode(myServo_Servomotor_PWMSignal_PIN_D3, OUTPUT);
- }
- void loop(void)
- {
- // Check if the vibration signal is detected
- if (digitalRead(vibrationSignal_PIN_D2) == HIGH) { // If vibrationSignal is HIGH
- // Activate the song by setting the pin LOW
- digitalWrite(activateSong_PIN_D4, LOW); // Activate the song
- delay(500); // Wait for 500ms
- digitalWrite(activateSong_PIN_D4, HIGH); // Set back to HIGH (input with pull-up)
- // Move the servo to 180 degrees
- myservo.write(180); // Move servo to 180 degrees
- delay(30000); // Maintain position for 30 seconds
- // Move the servo back to 0 degrees
- myservo.write(0); // Move servo back to 0 degrees
- }
- updateOutputs(); // Refresh output data
- }
- void updateOutputs()
- {
- // Write the raw data to the servo
- myservo.write(myServo_Servomotor_PWMSignal_PIN_D3_rawData); // Use Servo's write method
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement