Incorrect pin numbering and Analog read


New member
Something really weird is going on. I am using teensy 4.1 and I have a sketch that is using pin39 to read a tactile switch state and pin 38 and pin 4 to read an encoder state.
If I upload the pre-compiled version of the sketch (which was compiled two days ago) the sketch works fine and reads the tactile switch state and the encoder pulses.
If I upload exactly the same sketch that was compiled two days ago from the Arduino IDE - it compiles and then upload - the tactile switch state and encoder don't work. I have tried different things but nothing worked other than uploading the pre-compiled sketch.
After a lot of try and error I figured out that if I swap pin 38 and pin 39 in the sketch, compile and upload everything works again.
That makes no sense as the components are physically connected to pin 39 (switch) and pin 38-4 (encoder) and the pre-compiled sketch (which is using 39 for the switch and 38-4 for the encoder) works with no issue.
The only change I made yesterday before the problem started is trying to create a new joystick descriptor and changing the descriptor files. I've restored the original ones but I'm still getting the same weird behaviour. I've tried uploading the sketch from a different pc but I'm getting the same issue - I need to swap 39 and 38 to make it work.

Also analogRead of pin 21 gives me different value if done using the pre-compiled sketch and the compiled/uploaded sketch which again makes no sense.

Anyone able to help?

Without seeing the contents of your sketch, any guesses would be just that: pure guesses. Posting your sketch would at least allow others to take a look, & maybe then, some potential causes might be noticed. Posting your sketch would also allow others to compile & possibly run your code to see if the (mis)behavior can be independently confirmed. When you post code, make sure to use the "</>" button right above the text composition area, which will include your code in a way that it not only much easier to read, but also very easy to copy & paste into the Arduino IDE. It would also be useful to know which platform you are on (Windows, Mac, linux), what version of the Arduino IDE you are using, and which version of TeensyDuino you've installed.

Willing to help, but definitely needing more info to do so . . .

Mark J Culross