Analog channels
Analog channels are built at the bottom of the 10_TableAndAnalog.ino:
By default only one channel is set up, with a nonsense pin number and button number set to 0. If you don't have any analog switches, you can leave it like this.
Lets say we have 4 analog switches; two 12-position rotaries and two clutch paddles. We'll have to set up 4 analog channels.
This is how we've planned and wired the switches:
12-position switch, wired to pin A0, will have both 12-position and incremental mode. Should use button numbers 11-22 in 12-position mode and 23-24 in incremental mode.
12-position switch, wired to pin A5, will have only 12-position mode. Should use button numbers 0-11.
Master clutch paddle, wired to pin A3. Doesn't need any button numbers.
Slave clutch paddle, wired to pin A2. Doesn't need any button numbers.
Our code will look like this:
Note that we increased analogChannelCount
to 4. We also had add new elements to the arrays below to fill in the channel details.
To help visualize our channels:
Pin numbering is fairly straight forward. Button numbers follow the same rules as with encoders:
If your multiposition switch is used solely as an incremental switch, the starting button number goes in the top box. "0" in bottom box.
If your multiposition switch is used solely as a multiposition switch, the starting button number goes in the top box. "0" in bottom box.
If your multiposition switch uses a function with both multiposition mode and incremental mode, the starting button number for multiposition mode goes in the top box and starting button number for incremental mode goes in the bottom box.
Our 12-position switch on channel 2 starts with button number 0, so we'll keep the 0 in the top box. Clutches dont have button numbers, so they'll all stay at default 0. Actually, for a button number that isn't in use you can write anything. So if writing "12345" instead works better for you, go ahead. This goes for both analog channels and the switch table.
External ADCs and oversampling
The output channels wants to know a pin number. However, when you're using external ADCs you don't really have pin numbers. And when we activate oversampling for the RP2040, the ADC meassurements are piled up in a buffer and averaged, we're not reading them directly. So which pin numbers do we type in?
In these cases, we'll use the keyword "ADC", which makes all the functions for analog switches look for data in the right places.
Oversampling
When oversampling is enabled, you need to add a minimum of 4 analog channels, one for each pin (A0 - A3). Even if you're not using all 4 pins, you should still add 4 analog channels, since the process of oversampling requires some place to store the data - which would be in an analog channel. As mentioned above, we'll be using the keyword "ADC":
A0 -> ADC1
A1 -> ADC2
A2 -> ADC3
A3 -> ADC4
So, if we're looking at the case further up, an imagine this being an RP2040 board with oversampling enabled, it would look like this instead:
Lets say you're only using the A2 pin; you'd still have to set up all 4 channels like this and you'd be refering to channel 3 (ADC3) when using switch functions.
External ADC
When using external ADCs (ADS1115), you should set up 4 analog channels for each ADC chip. These will correspond to the A0 - A3 pins. With several ADCs you'll just have to keep adding 4 channels.
ADS1115 # 1:
A0 -> ACD1
A1 -> ADC2
A2 -> ADC3
A3 -> ADC4
ADS1115 #2:
A0 -> ADC5
A1 -> ADC6
A2 -> ADC7
A3 -> ADC8
..and so on.
Now, if you have enabled oversamling as well, the first 4 channels will be reserved, and your external ADCs will start on channel 5 with pin number "ADC5".
Reading a value
A lot of the functions handeling analog switches need some reference values, these will have to be read from the switch. DDC has a function to read a value from an analog pin or an external ADC channel, checkValue()
. If you have a pair of dual clutches on analog channels 3 and 4, just the readouts to 30_Switches.ino like this:
Upload the code and check the serial monitor for the values.
Remember to remove checkValue()
from your code when you're finishing the project, it can interfere a lot with the controllers communication with the computer.
With all this set up, you can start using your analog channels in 30_Switches.ino.
Last updated