Hi, everyone. I am so very frustrated with my inability to understand how this sketch is failing me. I have a Fritzing image at this link: https://dctech.tech/?page_id=500
I have removed all ez-button references, and I am just treating this like five “bouncing” inputs. Based on my sketch, pressing one of the five switches (grounding) D3, D6, D8, D9, or D10 should display an appropriate message on the SSD1306.
My problem is that inputs D3 and D6 just don’t work. Worse, adding a switch to D1 (which is not even declared) activates the down switch function.
I am very happy, at this point, to pay someone with a XIAO ESP32C3 and display and some momentary contact switches for their time to make this sketch work.
BTW - This sketch works great with my XIAO SAMD21, just not the ESP32C3, but I need Bluetooth capabilities.
/* This simple sketch demonstrates my ignorance of the ESP32C3 architecture. I extracted this code from a longer, functioning sketch for
* a XIAO SAMD21. I have left out the ezbutton commands for simplicity so, of course, there are bounce issues. That is not my problem.
* There is a Fritzing image accompanying this sketch. According to the sketch (IMHO), pushing any of the buttons
* connected to thefive digital inputs should trip the is fstatement and display one of five responses. The problem is, D3 and D6 do NOT
* respond to the digital inputs (taken LOW with a HIGH pullup). Worse yet, pressing the "ghost switch" in the Fritzing image drives
* digital pin D! low and activates the function otherwise controlled by the D6 input.
*
* My Questions:
* 1) How can I make this sketch work for the D3 and D6 inputs?
* 2) Why does grounding D1 activate the function that D6 is supposed to control?
*
* Thank you to anyone who solves this. Please send a copy of the corrected sketch to: [email protected]
*/
const int upButton = 6; // Up Button
const int downButton = 3; // Down Button
const int resetButton = 8; // Enter Button
const int leftButton = 10; // Left Button
const int rightButton = 9; // Right Button
#include "Wire.h"
#include <Adafruit_GFX.h> // Calls up the OLED graphics folder.
#include <fonts/Org_01.h>
#include <Adafruit_SSD1306.h> // Calls up the OLED display folder. // Holds the angular information.
#define OLED_RESET -1
Adafruit_SSD1306 display(OLED_RESET);
#define LOGO16_GLCD_HEIGHT 32 // Sets the display to 032 bits high
#define LOGO16_GLCD_WIDTH 128 // Sets the display to 128 bits long
void i2cSetup() {
// join I2C bus
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
Wire.begin();
#elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
Fastwire::setup(400, true);
#endif
}
void setup()
{
// initialize digital pins as inputs.
pinMode(resetButton, INPUT_PULLUP); // Initialize the pushbutton pin 9 as an input pullup . . .
pinMode(upButton, INPUT_PULLUP); // Initialize the pushbutton pin 10 as an input pullup . . .
pinMode(downButton, INPUT_PULLUP); // Initialize the pushbutton pin 8 as an input pullup . . .
pinMode(leftButton, INPUT_PULLUP); // Initialize the pushbutton pin 3 as an input pullup . . .
pinMode(rightButton, INPUT_PULLUP); // Initialize the pushbutton pin 6 as an input pullup . . .
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
while((digitalRead(resetButton) == HIGH ) and (digitalRead(upButton) == HIGH ) and (digitalRead(downButton) == HIGH ) and (digitalRead(leftButton) == HIGH ) and (digitalRead(rightButton) == HIGH )) // Begin the instruction loop to operate the device.
{
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.clearDisplay();
display.display();
display.invertDisplay(false);
display.print("Hold any ");
display.print("Button 4 #");
display.display();
if ((digitalRead(resetButton) == HIGH ) and (digitalRead(upButton) == HIGH ) and (digitalRead(downButton) == HIGH ) and (digitalRead(leftButton) == HIGH ) and (digitalRead(rightButton) == HIGH ))
{delay(2000);}
} // End of the WHILE instruction loop awaiting a data button push
for(int16_t i=0; i<display.height()/2; i+=2) {
display.display();
display.drawRect(i, i, display.width()-2*i, display.height()-2*i, SSD1306_WHITE);
}
}
// the loop function runs over and over again forever
void loop() {
if ((digitalRead(resetButton) == LOW ) and (digitalRead(upButton) == HIGH ) and (digitalRead(downButton) == HIGH ) and (digitalRead(leftButton) == HIGH ) and (digitalRead(rightButton) == HIGH ))
{
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.clearDisplay();
display.display();
display.invertDisplay(false);
display.print("Reset Button ");
display.display();
}
if ((digitalRead(resetButton) == HIGH) and (digitalRead(upButton) == LOW ) and (digitalRead(downButton) == HIGH ) and (digitalRead(leftButton) == HIGH ) and (digitalRead(rightButton) == HIGH ))
{
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.clearDisplay();
display.display();
display.invertDisplay(false);
display.print("Up Button ");
display.display();
}
if ((digitalRead(resetButton) == HIGH ) and (digitalRead(upButton) == HIGH ) and (digitalRead(downButton) == LOW ) and (digitalRead(leftButton) == HIGH ) and (digitalRead(rightButton) == HIGH ))
{
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.clearDisplay();
display.display();
display.invertDisplay(false);
display.print("Down Button ");
display.display();
}
if ((digitalRead(resetButton) == HIGH ) and (digitalRead(upButton) == HIGH ) and (digitalRead(downButton) == HIGH ) and (digitalRead(leftButton) == LOW ) and (digitalRead(rightButton) == HIGH ))
{
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.clearDisplay();
display.display();
display.invertDisplay(false);
display.print("Left Button ");
display.display();
}
if ((digitalRead(resetButton) == HIGH ) and (digitalRead(upButton) == HIGH ) and (digitalRead(downButton) == HIGH ) and (digitalRead(leftButton) == HIGH ) and (digitalRead(rightButton) == LOW ))
{
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.clearDisplay();
display.display();
display.invertDisplay(false);
display.print("Right Button ");
display.display();
}
}