Advertisement
pleasedontcode

Vibration Servo rev_113

Jul 24th, 2024
178
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:22:58
  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 a Servo object
  52. Servo myservo;  // Instantiate the Servo class
  53.  
  54. void setup(void)
  55. {
  56.     // put your setup code here, to run once:
  57.  
  58.     pinMode(vibrationSignal_PIN_D2, INPUT);
  59.     pinMode(activateSong_PIN_D4,    INPUT_PULLUP);
  60.  
  61.     pinMode(myServo_Servomotor_PWMSignal_PIN_D3,     OUTPUT);
  62.  
  63.     // Attach the Servo object to the PWM output pin
  64.     myservo.attach(myServo_Servomotor_PWMSignal_PIN_D3); // Attach the servo to pin D3
  65. }
  66.  
  67. void loop(void)
  68. {
  69.     // put your main code here, to run repeatedly:
  70.     if (digitalRead(vibrationSignal_PIN_D2) == HIGH) { // Check if vibration signal is HIGH
  71.         digitalWrite(activateSong_PIN_D4, LOW); // Activate song output LOW
  72.         delay(500); // Maintain LOW for 500ms
  73.         digitalWrite(activateSong_PIN_D4, HIGH); // Re-transform activateSong to HIGH (input with pull-up)
  74.  
  75.         myservo.write(180); // Move servo to 180°
  76.         delay(30000); // Maintain position for 30 seconds
  77.         myservo.write(0); // Move servo back to 0°
  78.     }
  79.  
  80.     updateOutputs(); // Refresh output data
  81. }
  82.  
  83. void updateOutputs()
  84. {
  85.     // Write the raw data to the servo
  86.     myservo.write(myServo_Servomotor_PWMSignal_PIN_D3_rawData); // Use the Servo library to set the servo position
  87. }
  88.  
  89. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement