Advertisement
pleasedontcode

Vibration Control rev_116

Jul 24th, 2024
184
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: Vibration Control
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-07-25 00:27:33
  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.  
  28. /****** DEFINITION OF LIBRARIES *****/
  29. #include <Servo.h>  //https://github.com/arduino-libraries/Servo
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34. void updateOutputs(void);
  35.  
  36. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  37. const uint8_t vibrationSignal_PIN_D2        = 2;
  38. const uint8_t activateSong_PIN_D4       = 4;
  39.  
  40. /***** DEFINITION OF PWM OUTPUT PINS *****/
  41. const uint8_t myServo_Servomotor_PWMSignal_PIN_D3       = 3;
  42.  
  43. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  44. /***** used to store raw data *****/
  45. uint8_t myServo_Servomotor_PWMSignal_PIN_D3_rawData     = 0;
  46.  
  47. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  48. /***** used to store data after characteristic curve transformation *****/
  49. float   myServo_Servomotor_PWMSignal_PIN_D3_phyData     = 0.0;
  50.  
  51. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  52. // Create an instance of the Servo class
  53. Servo myservo; // This initializes the Servo object
  54.  
  55. void setup(void)
  56. {
  57.     // Attach the Servo control to the PWM output pin
  58.     myservo.attach(myServo_Servomotor_PWMSignal_PIN_D3); // Attach the servo to pin D3
  59.  
  60.     pinMode(vibrationSignal_PIN_D2, INPUT);
  61.     pinMode(activateSong_PIN_D4,    INPUT_PULLUP);
  62.  
  63.     pinMode(myServo_Servomotor_PWMSignal_PIN_D3,     OUTPUT);
  64. }
  65.  
  66. void loop(void)
  67. {
  68.     // Check if the vibration signal is detected
  69.     if (digitalRead(vibrationSignal_PIN_D2) == HIGH) { // If vibrationSignal is HIGH
  70.         // Activate the song by setting the pin LOW
  71.         digitalWrite(activateSong_PIN_D4, LOW); // Activate the song
  72.         delay(500); // Wait for 500ms
  73.         digitalWrite(activateSong_PIN_D4, HIGH); // Set back to HIGH (input with pull-up)
  74.  
  75.         // Move the servo to 180 degrees
  76.         myservo.write(180); // Move servo to 180 degrees
  77.         delay(30000); // Maintain position for 30 seconds
  78.  
  79.         // Move the servo back to 0 degrees
  80.         myservo.write(0); // Move servo back to 0 degrees
  81.     }
  82.  
  83.     updateOutputs(); // Refresh output data
  84. }
  85.  
  86. void updateOutputs()
  87. {
  88.     // Write the raw data to the servo
  89.     myservo.write(myServo_Servomotor_PWMSignal_PIN_D3_rawData); // Use Servo's write method
  90. }
  91.  
  92. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement