I am using Arduino with mightyCore for software development.
I'm debugging a circuit board that has an atmega644 chip and has 3 pushbuttons (UI1, UI2, and UI3).
Each pushbutton is connected to a digital input with internal pullup.
I have verified with a DMM that these inputs are at 5V when pushbutton is not pressed and 0V when pressed.
But in this test program (button.ino) digitalRead always reports 0 whether or not the pushbutton is pressed.
It's hard to believe that a simple function like that isn't working.
Am I overlooking something simple?
// ============================================================================
// buttons.ino check digitalRead()
// ============================================================================
#define UI2 PIN_PC2
#define UI1 PIN_PC3
#define UI3 PIN_PC4
// init I/O pins
void iopin_init() {
pinMode(UI1, INPUT_PULLUP);
pinMode(UI2, INPUT_PULLUP);
pinMode(UI3, INPUT_PULLUP);
}
#define BAUD 115200
// startup init
void setup() {
iopin_init();
Serial.begin(BAUD);
}
uint8_t button1;
uint8_t button2;
uint8_t button3;
// main loop
void loop() {
button1 = digitalRead(UI1);
button2 = digitalRead(UI2);
button3 = digitalRead(UI3);
Serial.print(" ");
Serial.print(button1);
Serial.print(" ");
Serial.print(" ");
Serial.print(button2);
Serial.print(" ");
Serial.print(" ");
Serial.print(button3);
Serial.print("\r\n");
delay(500);
}