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: **Button Control**
- - Source Code NOT compiled for: ESP32 DevKit V1
- - Source Code created on: 2024-12-16 02:12:46
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* set pins d5,d18,d19,d23 to high. set pins D13, */
- /* D12, D14, D27 as mux pins s0, s1 ,s2 ,s3. add a */
- /* button to pin D26, when the input goes low, */
- /* increment the number to the mux. */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <EasyButton.h>
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- // Pin definitions
- const int muxPins[] = {D13, D12, D14, D27}; // MUX pins
- const int buttonPin = D26; // Button pin
- EasyButton button(buttonPin); // Create button object
- // MUX value
- int muxValue = 0;
- void setup(void)
- {
- // Set pins D5, D18, D19, D23 to HIGH
- pinMode(D5, OUTPUT);
- pinMode(D18, OUTPUT);
- pinMode(D19, OUTPUT);
- pinMode(D23, OUTPUT);
- digitalWrite(D5, HIGH);
- digitalWrite(D18, HIGH);
- digitalWrite(D19, HIGH);
- digitalWrite(D23, HIGH);
- // Set MUX pins as OUTPUT
- for (int i = 0; i < 4; i++) {
- pinMode(muxPins[i], OUTPUT);
- }
- // Initialize button
- button.begin();
- }
- void loop(void)
- {
- // Update button state
- button.update();
- // Check if the button is pressed
- if (button.isPressed()) {
- // Increment the mux value
- muxValue = (muxValue + 1) % 16; // Assuming a 4-bit MUX (0-15)
- // Set MUX pins according to the muxValue
- for (int i = 0; i < 4; i++) {
- digitalWrite(muxPins[i], (muxValue >> i) & 0x01);
- }
- }
- // Add a small delay to debounce the button
- delay(50);
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement