Advertisement
pleasedontcode

GearCarIndicator rev_01

Sep 17th, 2023 (edited)
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Arduino 3.30 KB | Software | 0 0
  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: GearCarIndicator
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2023-09-17 15:52:38
  15.     - Source Code generated by: James
  16.  
  17. ********* Pleasedontcode.com **********/
  18. /****** DEFINITION OF LIBRARIES *****/
  19. #include <Arduino.h>
  20. #include <Wire.h>
  21. #include <EasyButton.h>
  22. #include <Adafruit_SSD1306.h>
  23.  
  24. /****** SYSTEM REQUIREMENT 1 *****/
  25. /* The display shows the indication of the gear from */
  26. /* 1 to 6. At the startup, the system shall show "N" */
  27. /* as Neutral. */
  28. /****** SYSTEM REQUIREMENT 2 *****/
  29. /* If the gear up switch is released, so the gear */
  30. /* value shall be increased by 1. If the gear down */
  31. /* switch is released, so the gear value shall be */
  32. /* decreased by 1. */
  33.  
  34. /****** FUNCTION PROTOTYPES *****/
  35. void setup(void);
  36. void loop(void);
  37.  
  38. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  39. const uint8_t GearUp_PushButton_PIN_D2 = 2;
  40. const uint8_t GearDown_PushButton_PIN_D3 = 3;
  41.  
  42. /***** DEFINITION OF I2C PINS *****/
  43. const uint8_t display_SSD1306OledDisplay_I2C_PIN_SDA_A4 = A4;
  44. const uint8_t display_SSD1306OledDisplay_I2C_PIN_SCL_A5 = A5;
  45. const uint8_t display_SSD1306OledDisplay_I2C_SLAVE_ADDRESS = 60;
  46.  
  47. // Instantiate EasyButton objects for gear up and gear down buttons
  48. EasyButton gearUpButton(GearUp_PushButton_PIN_D2);
  49. EasyButton gearDownButton(GearDown_PushButton_PIN_D3);
  50.  
  51. // Instantiate SSD1306 display object
  52. Adafruit_SSD1306 display(display_SSD1306OledDisplay_I2C_SLAVE_ADDRESS);
  53.  
  54. void setup(void)
  55. {
  56.     // put your setup code here, to run once:
  57.  
  58.     pinMode(GearUp_PushButton_PIN_D2, INPUT_PULLUP);
  59.     pinMode(GearDown_PushButton_PIN_D3, INPUT_PULLUP);
  60.  
  61.     // Initialize the SSD1306 display
  62.     display.begin(SSD1306_SWITCHCAPVCC, display_SSD1306OledDisplay_I2C_SLAVE_ADDRESS);
  63.     display.clearDisplay();
  64.     display.setTextColor(WHITE);
  65.     display.setTextSize(2);
  66.     display.setCursor(0, 0);
  67.     display.println("N");
  68.     display.display();
  69. }
  70.  
  71. void loop(void)
  72. {
  73.     // put your main code here, to run repeatedly:
  74.  
  75.     // Check if the gear up button is released
  76.     if (gearUpButton.isReleased())
  77.     {
  78.         // Increase the gear value by 1
  79.         static uint8_t gear = 0;
  80.         gear++;
  81.         if (gear > 6)
  82.         {
  83.             gear = 6;
  84.         }
  85.  
  86.         // Update the display with the new gear value
  87.         display.clearDisplay();
  88.         display.setCursor(0, 0);
  89.         display.println(gear);
  90.         display.display();
  91.     }
  92.  
  93.     // Check if the gear down button is released
  94.     if (gearDownButton.isReleased())
  95.     {
  96.         // Decrease the gear value by 1
  97.         static uint8_t gear = 0;
  98.         if (gear > 0)
  99.         {
  100.             gear--;
  101.         }
  102.  
  103.         // Update the display with the new gear value
  104.         display.clearDisplay();
  105.         display.setCursor(0, 0);
  106.         display.println(gear);
  107.         display.display();
  108.     }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement