Is there a wrong way to set up inputs and outputs?
That was rhetorical. I'm sure there are plenty of terrible ways to attempt such a task. But I'm definitely having trouble with the inputs on my Teensy, and wanted to see if it's something I'm doing wrong or if there is some microscopic fine print in the documentation telling me I can't accomplish this task.
My controller board is basically divided in half - 20 pins acting as outputs (eventually to be connected to solenoid drivers) and 20 pins acting as inputs (to be connected to microswitches). I've written up a control system that links them together in the way I wanted, but have run into a little issue.
As is preferred practice, I've minimalized it into the smallest program that shows the problem. Here's some very simple test code, which works exactly as intended.
void setup() {
pinMode(13, OUTPUT);
pinMode(20, INPUT_PULLUP);
}
void loop() {
digitalWrite(13, !digitalRead(20)); // set the LED on
delay(20);
}
When I jumper across from ground to pin 20, the LED flicks on, and stays on until I disconnect the wire. Good. But then, I choose to set up a few more pins for output...
void setup() {
for(int i = 0; i < 20; ++i)
{
pinMode(i, OUTPUT);
}
pinMode(20, INPUT_PULLUP);
}
void loop() {
digitalWrite(13, !digitalRead(20)); // set the LED on
delay(20);
}
... and suddenly, as soon as I upload, the LED comes on and stays on, and remains that way regardless of how much I poke pin 20 with my probe wire. Individually activating the outputs shows that activating certain ones (including 8 and 19 for example) seem to trigger the problem.
This obviously puts a damper on my grand plans for this device. Is there some sort of setup that I need to do to make sure the pins behave as I want?