Advertisement
pleasedontcode

Obstacleavoidingrobot rev_01

Nov 21st, 2023
92
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: Obstacleavoidingrobot
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2023-11-21 06:51:02
  15.     - Source Code generated by: Pavan
  16.  
  17. ********* Pleasedontcode.com **********/
  18. /****** DEFINITION OF LIBRARIES *****/
  19. #include <Arduino.h>
  20. #include <EasyButton.h>
  21.  
  22. /****** SYSTEM REQUIREMENT 1 *****/
  23. /* Car will avoid the obstacle */
  24.  
  25. /****** FUNCTION PROTOTYPES *****/
  26. void setup(void);
  27. void loop(void);
  28.  
  29. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  30. const uint8_t Apm_PushButton_PIN_D2 = 2;
  31.  
  32. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  33. EasyButton button(Apm_PushButton_PIN_D2);
  34.  
  35. void buttonPressed()
  36. {
  37.   Serial.println("Button pressed");
  38.   // Add code here to make the car avoid the obstacle
  39. }
  40.  
  41. void sequenceEllapsed()
  42. {
  43.   Serial.println("Double click");
  44.   // Add code here to make the car avoid the obstacle
  45. }
  46.  
  47. void buttonISR()
  48. {
  49.   button.read();
  50. }
  51.  
  52. void setup(void)
  53. {
  54.   // put your setup code here, to run once:
  55.   pinMode(Apm_PushButton_PIN_D2, INPUT_PULLUP);
  56.  
  57.   // Initialize Serial for debugging purposes.
  58.   Serial.begin(115200);
  59.  
  60.   Serial.println();
  61.   Serial.println(">>> EasyButton interrupts example <<<");
  62.  
  63.   // Initialize the button.
  64.   button.begin();
  65.  
  66.   button.onPressed(buttonPressed);
  67.  
  68.   button.onSequence(2, 1500, sequenceEllapsed);
  69.  
  70.   if (button.supportsInterrupt())
  71.   {
  72.     button.enableInterrupt(buttonISR);
  73.     Serial.println("Button will be used through interrupts");
  74.   }
  75. }
  76.  
  77. void loop(void)
  78. {
  79.   // put your main code here, to run repeatedly:
  80.   button.read();
  81.   // Add code here to control the car's movement and avoid the obstacle
  82. }
  83.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement