Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: Display Control
- - Source Code NOT compiled for: ESP32 DevKit V1
- - Source Code created on: 2024-08-18 19:07:27
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Utilize Wokwi to interface a MAX7219 Dot Matrix */
- /* display with ESP32. Create a scrolling 9-character */
- /* message, incorporate an LED and push button, and */
- /* display button press status on the MAX7219. */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <EasyButton.h> // https://github.com/evert-arias/EasyButton
- #include <MD_MAX72XX.h> // Include the library for MAX7219 Dot Matrix display
- #include <SPI.h> // Include SPI library for communication with MAX7219
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t nn_PushButton_PIN_D4 = 4; // Pin for button D4
- const uint8_t nn_PushButton_PIN_D13 = 13; // Pin for button D13
- /***** DEFINITION OF MAX7219 DISPLAY PINS *****/
- #define MAX_DEVICES 1 // Number of MAX7219 devices
- #define DATA_IN 23 // Data pin connected to MAX7219
- #define CLK_PIN 18 // Clock pin connected to MAX7219
- #define LOAD_PIN 5 // Load pin connected to MAX7219
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- // Create instances of EasyButton for each button
- EasyButton buttonD4(nn_PushButton_PIN_D4); // Instance for button on pin D4
- EasyButton buttonD13(nn_PushButton_PIN_D13); // Instance for button on pin D13
- // Create an instance of the MAX7219 display
- MD_MAX72XX display = MD_MAX72XX(DATA_IN, CLK_PIN, LOAD_PIN, MAX_DEVICES);
- // Callback function for button D4 pressed
- void onButtonD4Pressed() {
- Serial.println("Button D4 pressed");
- display.clear(); // Clear the display
- display.print("D4 Pressed"); // Show button press status
- }
- // Callback function for button D13 pressed
- void onButtonD13Pressed() {
- Serial.println("Button D13 pressed");
- display.clear(); // Clear the display
- display.print("D13 Pressed"); // Show button press status
- }
- // Function to scroll a message on the display
- void scrollMessage(const char* message) {
- display.clear();
- display.setCursor(0, 0);
- display.print(message);
- display.update();
- delay(1000); // Delay to allow the message to be visible
- }
- void setup(void) {
- // Initialize Serial for debugging purposes
- Serial.begin(115200);
- Serial.println();
- Serial.println(">>> EasyButton example with multiple buttons <<<");
- // Initialize the buttons
- buttonD4.begin(); // Initialize button on pin D4
- buttonD13.begin(); // Initialize button on pin D13
- // Add callback functions for button presses
- buttonD4.onPressed(onButtonD4Pressed); // Set callback for button D4
- buttonD13.onPressed(onButtonD13Pressed); // Set callback for button D13
- // Initialize the MAX7219 display
- display.begin();
- display.setIntensity(5); // Set brightness level (0-15)
- display.clear(); // Clear the display at startup
- // Scroll a welcome message
- scrollMessage("Welcome!");
- }
- void loop(void) {
- // Continuously read the status of the buttons
- buttonD4.read(); // Read the state of button D4
- buttonD13.read(); // Read the state of button D13
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement