/********* 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:16:42 ********* 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 //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 to control the servo motor Servo myServo; // Instance of 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 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: updateOutputs(); // Refresh output data // Check if the vibration signal is HIGH (active) if (digitalRead(vibrationSignal_PIN_D2) == HIGH) { // Activate the song output digitalWrite(activateSong_PIN_D4, LOW); // Activate the song delay(500); // Wait for 500ms digitalWrite(activateSong_PIN_D4, HIGH); // Deactivate the song // 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 } } void updateOutputs() { // Write the raw data to the servo myServo.write(myServo_Servomotor_PWMSignal_PIN_D3_rawData); // Use the Servo object to control the servo } /* END CODE */