-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathFSP03CE_example.ino
68 lines (59 loc) · 2.1 KB
/
FSP03CE_example.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
Ohmite FSP test for FSP03CE round sensor
This example shows how to read position and force on a force-sensing potentiometer.
Running a finger around the sensor results in a position value from 0 to 100.
Pressing on the sensor produces a force value that varies from 0 to about 3.
It uses the M2aglabs_Ohmite library by Marc Graham:
https://github.com/m2ag-labs/m2aglabs_ohmite
https://m2aglabs.com/2019/08/14/using-ohmite-force-sensitive-potentiometers/
The circuit:
- 22Kohm resistor connects Vref (pin A4) to wiper (pin A3)
(changing the resistor value will change the positional range)
- sensor wiper (pin 4): A3
- sensor D120 (pin 3): A2
- sensor D0 (pin 2): A1
- sensor D240 (pin 1): A0
Note: wiper and Vref need to be on an analog pin, others can be digital pins
created 14 Jun 2020
by Tom Igoe
*/
#include "M2aglabs_Ohmite.h"
// threshold for the force sensing. Range is 0 to about 3:
const float threshold = 0.5;
//CHANGE THIS
// sensor is attached to pins A2-A1, with the external resistor going from A2 to A3:
// Same code can be used for FSP01CE and FSP02CE, by changing last parameter.
// FSP01CE: false, FSP02CE: true
M2aglabs_Ohmite sensor(A3, A4, A2, A1, A0);
void setup() {
Serial.begin(9600);
/*
begin() sets analog resolution and max voltage.
defaults are 10 and 3.3
for Uno, use 10 bits resolution and 5V
for MKR and Nano33, use 3.3V, and you can use up to 12 bits resolution
by setting analogReadResolution(12).
*/
sensor.begin(10, 3.3);
}
void loop() {
int pos; // Position is an integer
float force; // Force is a float
// get the force reading:
force = sensor.getForce();
Serial.print("force: ");
Serial.print(force);
// if the force is high enough, someone's touching the sensor,
// so get the position:
if (force > threshold) {
// position reads from 0 - 360
pos = sensor.getPosition();
// constrain it to 0-359 degrees (ish):
int angle = constrain(pos, 0, 359);
Serial.print(" position: ");
Serial.print(pos);
Serial.print(" angle: ");
Serial.print(angle);
}
Serial.println();
}