-
Notifications
You must be signed in to change notification settings - Fork 19
Function Selector
-
The robot has a four pole switch on it that can be used to select a program or function for the robot to perform. It also has a press button tactile switch that can be used in conjunction with the 4 pole switch as a user button.
-
The 4 pole switch is connected to resistors R2 to R5 so that the 4 switches short out different resistors that are wired in a series. As each of the resistors that are shorted out have a different value, the effect is to make a different analogue voltage appear on the function select pin of the Nano for each different 4 switch combination.
-
The user button is wired to connect the function select pin to 5 volts
-
By reading the function select pin as an analogue voltage we can distinguish 16 different analogue voltages for each combination of settings of the 4 pole switch, plus one extra value when the user button is pressed.
-
You should note that, although the switches are labelled 1 to 4, there is no guarantee that the actual switch device is mounted any particular way round or that the device you have used is numbered in exactly the same way. As far as the code is concerned the switch value is returned as a binary value with the least significant bit corresponding to the switch closest to the centre of the robot. Normally, the switches would be closed when pushed to the front of the robot and open when pushed to the rear of the robot. In that case, all the switches forward would return the value 15 and all the switches to the rear would return zero. If only the outermost switch is pushed forward, the returned value would be 8.
-
To write the program for this, you should make a test program to continuously read the analogue value of the function select pin and write it to the serial monitor. Then cycle the switches through each of the 16 combinations in sequence from 0000 to 1111, noting the value returned against each. Then write some code that tests for the mid-point values between the values noted earlier and returns a function value number in the corresponding range 0 to 15
-
If the value returned is close to the maximum value of 1023 then return a value showing that the user button has been pressed
Getting Started Pages
Building Guide
- Tools and Materials
- Assemble the main board
- Addendum for V1.3a main board
- Assemble the basic line sensor
- Assemble the mini wide line sensor board
- Assemble the basic wall sensor
- Mounting sensor boards
- Choosing motors
- Fitting Encoders
- Mounting the motors
- Choosing batteries
- Mounting the battery
Reference Pages
Troubleshooting
Developer Notes