Advertisement
pleasedontcode

Vibration Servo rev_111

Jul 24th, 2024
211
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:16:42
  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 to control the servo motor
  52. Servo myServo; // Instance of 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 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.  
  71.     updateOutputs(); // Refresh output data
  72.  
  73.     // Check if the vibration signal is HIGH (active)
  74.     if (digitalRead(vibrationSignal_PIN_D2) == HIGH) {
  75.         // Activate the song output
  76.         digitalWrite(activateSong_PIN_D4, LOW); // Activate the song
  77.         delay(500); // Wait for 500ms
  78.         digitalWrite(activateSong_PIN_D4, HIGH); // Deactivate the song
  79.  
  80.         // Move the servo to 180 degrees
  81.         myServo.write(180); // Move servo to 180 degrees
  82.         delay(30000); // Maintain position for 30 seconds
  83.  
  84.         // Move the servo back to 0 degrees
  85.         myServo.write(0); // Move servo back to 0 degrees
  86.     }
  87. }
  88.  
  89. void updateOutputs()
  90. {
  91.     // Write the raw data to the servo
  92.     myServo.write(myServo_Servomotor_PWMSignal_PIN_D3_rawData); // Use the Servo object to control the servo
  93. }
  94.  
  95. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement