I am running the 3Pi using Arduino and have run into an issue when reading the pushbuttons [using low level reads]. It works with the LCD module in place, but when the LCD is removed, it doesn’t work.
Best to first look at the code:
void setup() {
pinMode(1, OUTPUT); // red LED
pinMode(7, OUTPUT); // green LED
pinMode(9, INPUT); // pushbutton A
}
void loop() {
if(digitalRead(9) == HIGH) {
digitalWrite(1, HIGH); // red ON
digitalWrite(7, LOW); // green OFF
}
else {
digitalWrite(1, LOW); // red OFF
digitalWrite(7, HIGH); // green ON
}
}
The program is designed to read the state of digital pin 9 (button A on the 3Pi). When it’s HIGH, it turns on the red LED; LOW turns on the green LED. According to the pin assignment table (page 17 of the manual - 0J17) digital pin 9 is user pushbutton A, and pressing it pulls it LOW.
This is a bit irksome, as I was planning to create a “shield” that utilized pins 2, 4, 8 when the LCD module was removed.
I get the feeling that pin 9 is floating and is relying on the LCD module to pull it HIGH.
Any thoughts as to 1) if I’m doing something wrong, or 2) how to fix it.