Advertisement
pleasedontcode

Vibration Servo rev_115

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