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 Increment
- - Source Code compiled for: ESP32 DevKit V1
- - Source Code created on: 2024-12-16 02:45:24
- ********* 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 *****/
- /********* User code review feedback **********
- #### Feedback 1 ####
- - C:\Users\Craig\AppData\Local\Temp\.arduinoIDE-unsaved20241116-22
- 928-iq50t9.lf7t\sketch_dec16a\sketch_dec16a.ino:37:24: error: 'D
- 13' was not declared in this scope; did you mean 'A13'?
- 37 |
- const int muxPins[] = {D13, D12, D14, D27}; // MUX pins
- |
- ^~~
- |
- #### Feedback 2 ####
- - Add that when the button is pressed it is displayed on the seria
- l monitor, along with the count and the settings for the mux.
- Al
- so flash the internal LED for 1 second every time the button is
- pressed
- ********* User code review feedback **********/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <EasyButton.h>
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- // Pin definitions
- const int muxPins[] = {13, 12, 14, 27}; // MUX pins (Updated: Removed 'D' prefix)
- const int buttonPin = 26; // Button pin (Updated: Removed 'D' prefix)
- EasyButton button(buttonPin); // Create button object
- // MUX value
- int muxValue = 0;
- void setup(void)
- {
- // Set pins 5, 18, 19, 23 to HIGH
- pinMode(5, OUTPUT);
- pinMode(18, OUTPUT);
- pinMode(19, OUTPUT);
- pinMode(23, OUTPUT);
- digitalWrite(5, HIGH);
- digitalWrite(18, HIGH);
- digitalWrite(19, HIGH);
- digitalWrite(23, HIGH);
- // Set MUX pins as OUTPUT
- for (int i = 0; i < 4; i++) {
- pinMode(muxPins[i], OUTPUT);
- }
- // Initialize button
- button.begin();
- // Initialize Serial communication
- Serial.begin(9600);
- }
- 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);
- }
- // Display the button press count and mux settings on Serial Monitor
- Serial.print("Button pressed! Count: ");
- Serial.print(muxValue);
- Serial.print(" MUX settings: ");
- for (int i = 0; i < 4; i++) {
- Serial.print((muxValue >> i) & 0x01);
- if (i < 3) Serial.print(", ");
- }
- Serial.println();
- // Flash the internal LED for 1 second
- digitalWrite(LED_BUILTIN, HIGH);
- delay(1000);
- digitalWrite(LED_BUILTIN, LOW);
- }
- // Add a small delay to debounce the button
- delay(50);
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement