Not sure if I should start another thread :o
Board is a Teensy 2.0 (Teensyduino)
All pins in use, except for the LED, were set to INPUT_PULLUP. Similarly, pins not in use were listed as global variables and set to INPUT_PULLUP. (an array might be better here)
At start the sketch runs as designed - output to OLED is as expected. After a minute or so the sketch seems to freeze and outputs rubbish. For example, the temperature readout on the OLED goes to 50.00, which tends to indicate that the analog pin is not reading the sensor. Other readings are also screwy.
Not sure what follows is the right way of setting pull up resistors while also avoiding variable conflicts later in the sketch.
//pins in use - there are many more
#define LED 11
#define pin1 1
#define pin2 2
//pins not in use - there are many more
#define pin3 3
#define pin4 4
void setup() {
// pins in use
pinMode(LED, OUTPUT);
pinMode(pin1, INPUT_PULLUP);
pinMode(pin2, INPUT_PULLUP);
// and all the other pins except for analog pins and the SCL and SDA for the OLED?
//pins not in use
pinMode(pin3, INPUT_PULLUP);
pinMode(pin4, INPUT_PULLUP);
// many more pins as well
}
void loop() {}
Things that come to mind are; the original sketch only referenced the pins in use as global variables and pinMode. By adding a list of unused pins (#define) there could be a conflict of variables later in the body of the code? Reading the documentation, perhaps I should be using 'const int' instead of #define. If this is the case finding the issue will not be easy - for me anyway.
I don't want to risk running the sketch again until I get a better grasp of this.
Alternatively...
//pins in use - there are many more
#define LED 11
#define pin1 1
#define pin2 2
//pins not in use - there are many more
const int pin3 3
const int pin4 4
void setup() {
// pins in use
pinMode(LED, OUTPUT);
pinMode(pin1, INPUT_PULLUP);
pinMode(pin2, INPUT_PULLUP);
// and all the other pins except for analog pins and the SCL and SDA for the OLED?
//pins not in use
pinMode(pin3, INPUT_PULLUP);
pinMode(pin4, INPUT_PULLUP);
// many more pins as well
void loop() {}
}