With tile construction set, we now have to calibrate the reading of tiles and establish a "protocol" for mapping tiles to macros.
I'm using the same SS49E Linear Hall Effect Sensor that I did with the TMD-3 project so I know that the Analog To Digital (ADC) default reading from the sensor (with no magnetic field nearby) is the middle of the range. Furthermore a magnet with one polarity will move the reading to higher values while the opposite polarity moves it to a lower values. So I printed a tile slot and populated it with a single SS49E sensor. The sensor is pressed into a precisely sized and positioned indentation at the bottom of the slot with the leads extending below.
I wired the sensor to my pro Micro.
Pro Micro | SS49E |
---|---|
VCC | +5V |
GND | GND |
A0 | OUT |
I wrote a simple sketch to read the sensor.
/*
MacroPad Sensor Calibration.
*/
int sensorPin = A0; // Sensor input pin.
int sensorValue = 0; // Sensor value.
int sensorMid = 0;
void setup() {
Serial.begin(115200);
Serial.println("MacroPad Sensor Test!");
sensorMid = analogRead(sensorPin);
}
void loop() {
// Read the value from the sensor.
sensorValue = analogRead(sensorPin) - sensorMid;
if (abs(sensorValue) > 20) {
// Magnet detected.
Serial.println(sensorValue);
}
delay(1000);
}
Using this code I established the following table.
Assigned Number | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
---|---|---|---|---|---|---|---|---|
Magnet Distance | 0 mm | 1 mm | 2 mm | 3 mm | 0 mm | 1 mm | 2 mm | 3 mm |
Polarity | N | N | N | N | S | S | S | S |
Sensor Reading | 180 | 104 | 79 | 53 | -164 | -114 | -81 | -49 |
The important thing here is the first and last rows. If the value read from the sensor is "close" (there will always be a little variance between different sensors and tiles) to one of the values in the last row, then that position will be assigned to the number in the first row from the same column. So for instance if the sensor value read is say 50, then the value for that position will be assigned a value of 3.
Remember that each slot has two sensors. When you drop in a tile, the assigned value from the left position will be combined with the assigned value from the right position to form a two digit "key" that will map to a specific macro. Astute readers will realize that each tile will thus have a valid two digit octal number key associated with it. Of course care must be taken to make sure that all tiles have a unique key.
So here are my first 12 tiles ready to have the top labels attached.
12 down 52 to go.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.