30_Switches.ino
Last updated
Last updated
This is where you add all your switches. Go to the and find something that suits your needs. Anything you write here should be between the hard-to-miss warnings "SWITCHES START HERE" and "SWITCHES END HERE"
A simple pushbutton on row 3, column 1 would be written as pushButton(3,1);
With matrix wiring or shift register wiring, you will just use the switch table adresses in the switch functions as explained However, with , you'll have to add some extra lines.
You might have asked yourself how your direct wired switches has found their way to the switch table so far. They haven't, they're still floating around. Your direct wired switches needs to have their values read and that value conveyed to a dedicated adress in the table. From there, the switch now behaves as any switch in the switch table, and allows you to use any fuction that works with a matrix wired or shift register wired button.
The switchTableInject()
function shold be used for every pin on the Arduino that is used for direct wired switches.
The function needs to know the pin number to read, the table row and the table column. Like this:
switchTableInject(pin, row, column);
If you planned with an encoder on row 1, using column 1 and 2, and using physical Arduino pins 10 and 14, add this:
switchTableInject(10, 1, 1);
switchTableInject(14, 1, 2);
If you planned with a button on row 2, using column 5, and using physical Arduino pin 9, add this:
switchTableInject(9, 2, 5);
All instances of switchTableInject()
should be called before any switch functions.
This is what the empty 30_Switches looks like:
A full (and rather feature rich) steering wheel could look like this: