Advertisement
pleasedontcode

Arduino Setup rev_01

Dec 28th, 2023
82
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: Arduino Setup
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2023-12-28 23:23:56
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Si la distancia del sensor es menor que 10 */
  21.     /* entonces coloque el servo a 90° */
  22. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24. /****** DEFINITION OF LIBRARIES *****/
  25. #include <Arduino.h>
  26. #include <Ultrasonic.h>
  27. #include <Servo.h>
  28.  
  29. /****** FUNCTION PROTOTYPES *****/
  30. void setup(void);
  31. void loop(void);
  32.  
  33. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  34. const uint8_t Ultra1_HC_SR04_Echo_PIN_D3 = 3;
  35.  
  36. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  37. const uint8_t Ultra1_HC_SR04_Trigger_PIN_D2 = 2;
  38.  
  39. /***** DEFINITION OF PWM OUTPUT PINS *****/
  40. const uint8_t Servo1_Servomotor_PWMSignal_PIN_D5 = 5;
  41.  
  42. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  43. Ultrasonic ultrasonic(Ultra1_HC_SR04_Trigger_PIN_D2, Ultra1_HC_SR04_Echo_PIN_D3);
  44. Servo servo;
  45.  
  46. void setup(void)
  47. {
  48.   // put your setup code here, to run once:
  49.   pinMode(Ultra1_HC_SR04_Echo_PIN_D3, INPUT);
  50.   pinMode(Ultra1_HC_SR04_Trigger_PIN_D2, OUTPUT);
  51.   pinMode(Servo1_Servomotor_PWMSignal_PIN_D5, OUTPUT);
  52.  
  53.   servo.attach(Servo1_Servomotor_PWMSignal_PIN_D5);
  54. }
  55.  
  56. void loop(void)
  57. {
  58.   // put your main code here, to run repeatedly:
  59.   unsigned int distance = ultrasonic.read();
  60.  
  61.   if (distance < 10)
  62.   {
  63.     servo.write(90); // Set servo angle to 90 degrees
  64.   }
  65.  
  66.   delay(1000);
  67. }
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement