Advertisement
pleasedontcode

Display Control rev_01

Aug 18th, 2024
125
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: Display Control
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2024-08-18 19:07:27
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Utilize Wokwi to interface a MAX7219 Dot Matrix */
  21.     /* display with ESP32. Create a scrolling 9-character */
  22.     /* message, incorporate an LED and push button, and */
  23.     /* display button press status on the MAX7219. */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /****** DEFINITION OF LIBRARIES *****/
  27. #include <EasyButton.h>  // https://github.com/evert-arias/EasyButton
  28. #include <MD_MAX72XX.h>  // Include the library for MAX7219 Dot Matrix display
  29. #include <SPI.h>         // Include SPI library for communication with MAX7219
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34.  
  35. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  36. const uint8_t nn_PushButton_PIN_D4 = 4;   // Pin for button D4
  37. const uint8_t nn_PushButton_PIN_D13 = 13; // Pin for button D13
  38.  
  39. /***** DEFINITION OF MAX7219 DISPLAY PINS *****/
  40. #define MAX_DEVICES 1        // Number of MAX7219 devices
  41. #define DATA_IN   23         // Data pin connected to MAX7219
  42. #define CLK_PIN   18         // Clock pin connected to MAX7219
  43. #define LOAD_PIN  5          // Load pin connected to MAX7219
  44.  
  45. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  46. // Create instances of EasyButton for each button
  47. EasyButton buttonD4(nn_PushButton_PIN_D4);  // Instance for button on pin D4
  48. EasyButton buttonD13(nn_PushButton_PIN_D13); // Instance for button on pin D13
  49.  
  50. // Create an instance of the MAX7219 display
  51. MD_MAX72XX display = MD_MAX72XX(DATA_IN, CLK_PIN, LOAD_PIN, MAX_DEVICES);
  52.  
  53. // Callback function for button D4 pressed
  54. void onButtonD4Pressed() {
  55.     Serial.println("Button D4 pressed");
  56.     display.clear(); // Clear the display
  57.     display.print("D4 Pressed"); // Show button press status
  58. }
  59.  
  60. // Callback function for button D13 pressed
  61. void onButtonD13Pressed() {
  62.     Serial.println("Button D13 pressed");
  63.     display.clear(); // Clear the display
  64.     display.print("D13 Pressed"); // Show button press status
  65. }
  66.  
  67. // Function to scroll a message on the display
  68. void scrollMessage(const char* message) {
  69.     display.clear();
  70.     display.setCursor(0, 0);
  71.     display.print(message);
  72.     display.update();
  73.     delay(1000); // Delay to allow the message to be visible
  74. }
  75.  
  76. void setup(void) {
  77.     // Initialize Serial for debugging purposes
  78.     Serial.begin(115200);
  79.     Serial.println();
  80.     Serial.println(">>> EasyButton example with multiple buttons <<<");
  81.  
  82.     // Initialize the buttons
  83.     buttonD4.begin(); // Initialize button on pin D4
  84.     buttonD13.begin(); // Initialize button on pin D13
  85.  
  86.     // Add callback functions for button presses
  87.     buttonD4.onPressed(onButtonD4Pressed); // Set callback for button D4
  88.     buttonD13.onPressed(onButtonD13Pressed); // Set callback for button D13
  89.  
  90.     // Initialize the MAX7219 display
  91.     display.begin();
  92.     display.setIntensity(5); // Set brightness level (0-15)
  93.     display.clear(); // Clear the display at startup
  94.  
  95.     // Scroll a welcome message
  96.     scrollMessage("Welcome!");
  97. }
  98.  
  99. void loop(void) {
  100.     // Continuously read the status of the buttons
  101.     buttonD4.read(); // Read the state of button D4
  102.     buttonD13.read(); // Read the state of button D13
  103. }
  104.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement