Teensy functionality controlled by DIP switches

Status
Not open for further replies.

Jake

Well-known member
I am new to embedded programming and don't consider myself a programmer, but have done some. In the embedded world, I have only used the Teensy 3.1 with Teenduino.

In effect, what I would like to do is to have a DIP switch connected to the Teensy to control its functionality. When the Teensy is powered on it will read the DIP switches, and depending upon the switch settings, have the Teensy perform different functions. In the ideal world, this would control which program of multiple programs loaded into the Teensy would be executed. However, my understanding is that this is not possible.

A potential method of doing this would be to have different blocks of code in the loop part of the program. The execution of these blocks could be controlled by if statements or possibly the switch statement with values from the DIP switch.

Are there more elegant ways of having different programs run or different functionality depending upon the DIP switch settings?
 
Do you need the loop functionality? Otherwise, just do all the programming with setup(). Read the dip switches and decide which of several programs to execute during the setup() routine. You never have to exit setup().

TLB
 
Or use loop solely to do a digital read of each dip channel and go down that path based on the interpreted setting.
 
Multiple blocks of code compiled into 1 program, which first uses pinMode() and digitalRead() to check the switches, would be the easiest and best path.

If you *really* want to make this incredible complicated and difficult, you could try to compile separate programs. Each will need its own custom linker script, to compile it to reside in a non-conflicting portion of the memory. Then you'd need to create a script or program to combine them all together.

If you wanted to take something that's already hard and make it dangerous too, you could even try to create a self-modifying program. But as we've recently seen, playing with the flash controller is quite risky.

Your best path by far is to combine the programs at the source code level and compile together into a single upload, with a small amount of code to read the switches and run the designed function.
 
Status
Not open for further replies.
Back
Top