Advertisement
pleasedontcode

Vibration Servo rev_114

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