You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#include"inputs-LSM6DS3.h"//definitions for your own functions - needed only if calling functions before they're defined
7
+
#include"controller.h"//ctrlEvt
8
+
9
+
// Hardware inputs and value setting
10
+
byte btnCur = 0; //Momentary button currently in use - only one allowed at a time
11
+
byte btnCurHeld = 0; //Button hold thresholds: 0=none, 1=unused, 2=short, 3=long, 4=verylong, 5=superlong, 10=set by btnStop()
12
+
unsignedlong inputLast = 0; //When a button was last pressed
13
+
unsignedlong inputLast2 = 0; //Second-to-last of above
14
+
//TODO the math between these two may fail very rarely due to millis() rolling over while setting. Need to find a fix. I think it only applies to the rotary encoder though.
15
+
int inputLastTODMins = 0; //time of day, in minutes past midnight, when button was pressed. Used in paginated functions so they all reflect the same TOD.
16
+
17
+
//IMU "debouncing"
18
+
int imuYState = 0; //the state we're reporting (-1, 0, 1)
19
+
int imuYTestState = 0; //the state we've actually last seen
20
+
int imuYTestCount = 0; //how many times we've seen it
21
+
int imuZState = 0; //the state we're reporting (-1, 0, 1)
22
+
int imuZTestState = 0; //the state we've actually last seen
23
+
int imuZTestCount = 0; //how many times we've seen it
24
+
25
+
26
+
voidinputsSetup(){
27
+
if(!IMU.begin()){ Serial.println("Failed to initialize IMU!"); while(1); }
28
+
// Serial.print("Accelerometer sample rate = ");
29
+
// Serial.print(IMU.accelerationSampleRate());
30
+
// Serial.println(" Hz");
31
+
// Serial.println();
32
+
// Serial.println("Acceleration in G's");
33
+
// Serial.println("X\tY\tZ");
34
+
35
+
// vertical: x=1, y=0, z=0
36
+
// forward: x=0, y=0, z=1
37
+
/// f a bit 0.8 0 0.7
38
+
// bakward: x=0. y=0, z=-1
39
+
// b a bit 0.8 0 -0.5
40
+
//left: x=0, y=1, z=0
41
+
//right: -1
42
+
//upside -1 0 0
43
+
}
44
+
voidinputsLoop(){
45
+
float x, y, z;
46
+
IMU.readAcceleration(x,y,z);
47
+
int imuState;
48
+
//Assumes Arduino is oriented with components facing back of clock, and USB port facing up
49
+
if(y<=-0.5) imuState = -1;
50
+
elseif(y>= 0.5) imuState = 1;
51
+
elseif(y>-0.3 && y<0.3) imuState = 0;
52
+
else imuState = imuYTestState; //if it's not in one of the ranges, treat it as "same"
ctrlEvt(btn,2); //hey, the button has been short-held
111
+
}
112
+
}
113
+
//If the button has just been released...
114
+
if(btnCur==btn && bnow==HIGH) {
115
+
btnCur = 0;
116
+
if(btnCurHeld < 10) ctrlEvt(btn,0); //hey, the button was released //4 to 10
117
+
btnCurHeld = 0;
118
+
}
119
+
}
120
+
voidbtnStop(){
121
+
//In some cases, when handling btn evt 1/2/3, we may call this so following events 2/3/0 won't cause unintended behavior (e.g. after a fn change, or going in or out of set) //4 to 10
0 commit comments