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: Sensor Controller
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2025-07-27 10:43:04
- ********* 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
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void handleVibrationAndServo();
- /***** 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 OUTPUT RAW VARIABLES *****/
- /***** used to store raw data *****/
- bool myActiveBuzzer_ActiveBuzzer_output_PIN_D5_rawData = 0;
- uint8_t myServo_Servomotor_PWMSignal_PIN_D3_rawData = 0;
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- /***** used to store data after characteristic curve transformation *****/
- float myActiveBuzzer_ActiveBuzzer_output_PIN_D5_phyData = 0.0;
- float myServo_Servomotor_PWMSignal_PIN_D3_phyData = 0.0;
- /****** LIBRARY CLASS INSTANCES*****/
- Servo myServo; // create Servo object to control a servo
- 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);
- pinMode(myServo_Servomotor_PWMSignal_PIN_D3, OUTPUT);
- myServo.attach(myServo_Servomotor_PWMSignal_PIN_D3);
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- handleVibrationAndServo();
- updateOutputs();
- }
- void handleVibrationAndServo()
- {
- int vibrationSignal = digitalRead(vibrationSignal_PIN_D2);
- int activateSong = digitalRead(activateSong_PIN_D4);
- if (vibrationSignal == HIGH)
- {
- // Activate the song output LOW for 500ms
- digitalWrite(myActiveBuzzer_ActiveBuzzer_output_PIN_D5, LOW);
- delay(500);
- // Revert activateSong pin to input with pull-up
- pinMode(activateSong_PIN_D4, INPUT_PULLUP);
- // Move servo to 180°
- myServo.write(180);
- // Maintain position for 30 seconds
- delay(30000);
- // Move servo back to 0°
- myServo.write(0);
- }
- else
- {
- // If no vibration, ensure activateSong is HIGH (assuming active HIGH)
- digitalWrite(myActiveBuzzer_ActiveBuzzer_output_PIN_D5, HIGH);
- }
- }
- void updateOutputs()
- {
- digitalWrite(myActiveBuzzer_ActiveBuzzer_output_PIN_D5, myActiveBuzzer_ActiveBuzzer_output_PIN_D5_rawData);
- analogWrite(myServo_Servomotor_PWMSignal_PIN_D3, myServo_Servomotor_PWMSignal_PIN_D3_rawData);
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment