Advertisement
pleasedontcode

Input Setup rev_01

Mar 17th, 2024
20
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: Input Setup
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-03-17 18:42:47
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* using Arduino Mega, 28byj-48, IR Speed sensor, I2C */
  21.     /* LCD Display 16x2, forward limit switch, and */
  22.     /* reverse limit switch. By creating a Navigation */
  23.     /* menu through a rotary encoder(HW-040). */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /****** DEFINITION OF LIBRARIES *****/
  27. #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
  28. #include <Wire.h> // For I2C communication
  29. #include <LiquidCrystal_I2C.h> // For LCD display
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34.  
  35. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  36. const uint8_t button_PushButton_PIN_D2 = 2;
  37. const uint8_t limitSwitch_Forward_PIN = 3;
  38. const uint8_t limitSwitch_Reverse_PIN = 4;
  39. const uint8_t rotaryEncoder_CLK_PIN = 5;
  40. const uint8_t rotaryEncoder_DT_PIN = 6;
  41. const uint8_t rotaryEncoder_SW_PIN = 7;
  42. const uint8_t speedSensor_PIN = 8;
  43.  
  44. /****** DEFINITION OF LIBRARIES CLASS INSTANCES *****/
  45. EasyButton button_PushButton(button_PushButton_PIN_D2);
  46. LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 columns, 2 rows
  47.  
  48. void setup(void)
  49. {
  50.   // put your setup code here, to run once:
  51.  
  52.   pinMode(button_PushButton_PIN_D2, INPUT_PULLUP);
  53.   pinMode(limitSwitch_Forward_PIN, INPUT_PULLUP);
  54.   pinMode(limitSwitch_Reverse_PIN, INPUT_PULLUP);
  55.   pinMode(rotaryEncoder_CLK_PIN, INPUT_PULLUP);
  56.   pinMode(rotaryEncoder_DT_PIN, INPUT_PULLUP);
  57.   pinMode(rotaryEncoder_SW_PIN, INPUT_PULLUP);
  58.   pinMode(speedSensor_PIN, INPUT);
  59.  
  60.   // Initialize the EasyButton object with the pin number
  61.   button_PushButton.begin();
  62.  
  63.   // Initialize the LCD display
  64.   lcd.begin(16, 2);
  65.   lcd.setCursor(0, 0);
  66.   lcd.print("Navigation Menu");
  67. }
  68.  
  69. void loop(void)
  70. {
  71.   // put your main code here, to run repeatedly:
  72.  
  73.   // Call the EasyButton read() function to check for button events
  74.   if (button_PushButton.read())
  75.   {
  76.     // Button is pressed
  77.     // Add your code here to handle the button press event
  78.   }
  79.  
  80.   // Add your code here to read the other inputs and handle the navigation menu
  81. }
  82.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement