-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathArduinoPressurePad
More file actions
37 lines (30 loc) · 1.43 KB
/
ArduinoPressurePad
File metadata and controls
37 lines (30 loc) · 1.43 KB
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
#include <AccelStepper.h>
#define step_pin 3
#define dir_pin 2
#define M0 4
#define M1 5
#define M2 6
#define pressure A0
// Create an instance of the AccelStepper class
AccelStepper stepper(1, step_pin, dir_pin);
void setup() {
Serial.begin(9600);
pinMode(M0, OUTPUT);
pinMode(M1, OUTPUT);
pinMode(M2, OUTPUT);
pinMode(pressure, INPUT);
pinMode(dir_pin, OUTPUT);
}
void loop() {
digitalWrite(dir_pin, HIGH); // direction enabled
digitalWrite(M0, LOW);
digitalWrite(M1, LOW);
digitalWrite(M2, LOW);
//pressure can be 0-1023
// fill it in with pressure dependent speed! think about what intervals you would want and how much you would want the speed to change by for each interval.
// notes: analogRead(pressure) will get you the value from the pressure pad from 0-1023 that tells you how hard it is being clicked
// - if the value is 0, the pressure pad is not being pressed at all. Be sure to account for a small error due to the sensitivity of the pressure pad (ex. if it reads a value slightly over 0 like 10, it's probably not being pressed intentionally)
// - stepper.setSpeed(x); - will set the speed to the value of x. the range of speeds is from 0-600. it can technically be negative too, but don't worry about that quite yet.
// --> something to think about: what WOULD happen if you set the speed to a negative value?
// - stepper.runSpeed(); - will run the motor at the speed you set previously.
}