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:22:58
- ********* 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 a Servo object
- Servo myservo; // Instantiate the Servo class
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(vibrationSignal_PIN_D2, INPUT);
- pinMode(activateSong_PIN_D4, INPUT_PULLUP);
- pinMode(myServo_Servomotor_PWMSignal_PIN_D3, OUTPUT);
- // Attach the Servo object to the PWM output pin
- myservo.attach(myServo_Servomotor_PWMSignal_PIN_D3); // Attach the servo to pin D3
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- if (digitalRead(vibrationSignal_PIN_D2) == HIGH) { // Check if vibration signal is HIGH
- digitalWrite(activateSong_PIN_D4, LOW); // Activate song output LOW
- delay(500); // Maintain LOW for 500ms
- digitalWrite(activateSong_PIN_D4, HIGH); // Re-transform activateSong to HIGH (input with pull-up)
- myservo.write(180); // Move servo to 180°
- delay(30000); // Maintain position for 30 seconds
- myservo.write(0); // Move servo back to 0°
- }
- updateOutputs(); // Refresh output data
- }
- void updateOutputs()
- {
- // Write the raw data to the servo
- myservo.write(myServo_Servomotor_PWMSignal_PIN_D3_rawData); // Use the Servo library to set the servo position
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement