Advertisement
pleasedontcode

obstacleavoidingcar rev_02

Nov 23rd, 2023
87
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: obstacleavoidingcar
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2023-11-23 07:29:28
  15.     - Source Code generated by: jeffrin
  16.  
  17. ********* Pleasedontcode.com **********/
  18. /****** DEFINITION OF LIBRARIES *****/
  19. #include <Arduino.h>
  20. #include <EasyButton.h>
  21. #include <Servo.h>
  22.  
  23. /****** SYSTEM REQUIREMENT 1 *****/
  24. /* turn off the light */
  25. const uint8_t lightPin = 9;
  26.  
  27. /****** FUNCTION PROTOTYPES *****/
  28. void setup(void);
  29. void loop(void);
  30. void turnOffLight();
  31.  
  32. /***** DEFINITION OF PWM OUTPUT PINS *****/
  33. const uint8_t myservo_Servomotor_PWMSignal_PIN_D3 = 3;
  34.  
  35. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  36. Servo myservo;
  37. EasyButton button(2); // Replace 2 with the pin number connected to the button
  38.  
  39. void setup(void)
  40. {
  41.   // put your setup code here, to run once:
  42.   pinMode(lightPin, OUTPUT);
  43.   digitalWrite(lightPin, HIGH); // Turn off the light initially
  44.  
  45.   pinMode(myservo_Servomotor_PWMSignal_PIN_D3, OUTPUT);
  46.   myservo.attach(myservo_Servomotor_PWMSignal_PIN_D3);
  47.  
  48.   // Initialize button object
  49.   button.begin();
  50.   button.onPressed(turnOffLight); // Call turnOffLight function when button is pressed
  51. }
  52.  
  53. void loop(void)
  54. {
  55.   // put your main code here, to run repeatedly:
  56.   button.read(); // Read button state
  57.  
  58.   // Add your other code here
  59. }
  60.  
  61. void turnOffLight()
  62. {
  63.   digitalWrite(lightPin, LOW); // Turn off the light
  64. }
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement