pleasedontcode

Sensor Controller rev_117

Jul 27th, 2025
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: Sensor Controller
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2025-07-27 10:43:04
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* if vibrationSignal == 1, so transform activateSong */
  21.     /* in output and activate it LOW for 500ms and then */
  22.     /* retransform activateSong in digital input with */
  23.     /* pull up again. Then move servo to 180°, maintain */
  24.     /* it for 30 seconds and then go back again to 0°. */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27. /* START CODE */
  28.  
  29. /****** DEFINITION OF LIBRARIES *****/
  30. #include <Servo.h> //https://github.com/arduino-libraries/Servo
  31.  
  32. /****** FUNCTION PROTOTYPES *****/
  33. void setup(void);
  34. void loop(void);
  35. void handleVibrationAndServo();
  36.  
  37. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  38. const uint8_t vibrationSignal_PIN_D2 = 2;
  39. const uint8_t activateSong_PIN_D4 = 4;
  40.  
  41. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  42. const uint8_t myActiveBuzzer_ActiveBuzzer_output_PIN_D5 = 5;
  43.  
  44. /***** DEFINITION OF PWM OUTPUT PINS *****/
  45. const uint8_t myServo_Servomotor_PWMSignal_PIN_D3 = 3;
  46.  
  47. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  48. /***** used to store raw data *****/
  49. bool myActiveBuzzer_ActiveBuzzer_output_PIN_D5_rawData = 0;
  50. uint8_t myServo_Servomotor_PWMSignal_PIN_D3_rawData = 0;
  51.  
  52. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  53. /***** used to store data after characteristic curve transformation *****/
  54. float myActiveBuzzer_ActiveBuzzer_output_PIN_D5_phyData = 0.0;
  55. float myServo_Servomotor_PWMSignal_PIN_D3_phyData = 0.0;
  56.  
  57. /****** LIBRARY CLASS INSTANCES*****/
  58. Servo myServo; // create Servo object to control a servo
  59.  
  60. void setup(void)
  61. {
  62.   // put your setup code here, to run once:
  63.   pinMode(vibrationSignal_PIN_D2, INPUT);
  64.   pinMode(activateSong_PIN_D4, INPUT_PULLUP);
  65.  
  66.   pinMode(myActiveBuzzer_ActiveBuzzer_output_PIN_D5, OUTPUT);
  67.   pinMode(myServo_Servomotor_PWMSignal_PIN_D3, OUTPUT);
  68.  
  69.   myServo.attach(myServo_Servomotor_PWMSignal_PIN_D3);
  70. }
  71.  
  72. void loop(void)
  73. {
  74.   // put your main code here, to run repeatedly:
  75.   handleVibrationAndServo();
  76.   updateOutputs();
  77. }
  78.  
  79. void handleVibrationAndServo()
  80. {
  81.   int vibrationSignal = digitalRead(vibrationSignal_PIN_D2);
  82.   int activateSong = digitalRead(activateSong_PIN_D4);
  83.  
  84.   if (vibrationSignal == HIGH)
  85.   {
  86.     // Activate the song output LOW for 500ms
  87.     digitalWrite(myActiveBuzzer_ActiveBuzzer_output_PIN_D5, LOW);
  88.     delay(500);
  89.     // Revert activateSong pin to input with pull-up
  90.     pinMode(activateSong_PIN_D4, INPUT_PULLUP);
  91.     // Move servo to 180°
  92.     myServo.write(180);
  93.     // Maintain position for 30 seconds
  94.     delay(30000);
  95.     // Move servo back to 0°
  96.     myServo.write(0);
  97.   }
  98.   else
  99.   {
  100.     // If no vibration, ensure activateSong is HIGH (assuming active HIGH)
  101.     digitalWrite(myActiveBuzzer_ActiveBuzzer_output_PIN_D5, HIGH);
  102.   }
  103. }
  104.  
  105. void updateOutputs()
  106. {
  107.   digitalWrite(myActiveBuzzer_ActiveBuzzer_output_PIN_D5, myActiveBuzzer_ActiveBuzzer_output_PIN_D5_rawData);
  108.   analogWrite(myServo_Servomotor_PWMSignal_PIN_D3, myServo_Servomotor_PWMSignal_PIN_D3_rawData);
  109. }
  110.  
  111. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment