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
#defineCTRL_SEL A2 //main select button - must be equipped
3
+
#defineCTRL_UP A1 //main up/down buttons or rotary encoder - must be equipped
4
+
#defineCTRL_DN A0
5
+
6
+
#defineROT_VEL_START80//if encoder step rate falls below this, kick into high velocity set (x10)
7
+
#defineROT_VEL_STOP500//if encoder step rate rises above this, drop into low velocity set (x1)
8
+
9
+
//This clock is 2x3 multiplexed: two tubes powered at a time.
10
+
//The anode channel determines which two tubes are powered,
11
+
//and the two SN74141 cathode driver chips determine which digits are lit.
12
+
//4 pins out to each SN74141, representing a binary number with values [1,2,4,8]
13
+
#defineOUT_A12
14
+
#defineOUT_A23
15
+
#defineOUT_A34
16
+
#defineOUT_A45
17
+
#defineOUT_B16
18
+
#defineOUT_B27
19
+
#defineOUT_B38
20
+
#defineOUT_B49
21
+
//3 pins out to anode channel switches
22
+
#defineANODE_111
23
+
#defineANODE_212
24
+
#defineANODE_313
25
+
26
+
27
+
#include<Wire.h>
28
+
#include<Encoder.h>
29
+
Encoder rot(CTRL_DN,CTRL_UP);
30
+
31
+
32
+
byte theVal = 0;
33
+
34
+
35
+
////////// Main code control //////////
36
+
37
+
voidsetup(){
38
+
Serial.begin(9600);
39
+
Wire.begin();
40
+
initInputs();
41
+
initOutputs();
42
+
updateDisplay();
43
+
}
44
+
45
+
voidloop(){
46
+
checkInputs(); //if inputs have changed, this will do things + updateDisplay as needed
47
+
cycleDisplay(); //keeps the display hardware multiplexing cycle going
48
+
//TODO why isn't the display working
49
+
}
50
+
51
+
52
+
////////// Control inputs //////////
53
+
voidinitInputs(){
54
+
//TODO are there no "loose" pins left floating after this? per https://electronics.stackexchange.com/q/37696/151805
55
+
pinMode(CTRL_SEL, INPUT_PULLUP);
56
+
pinMode(CTRL_UP, INPUT_PULLUP);
57
+
pinMode(CTRL_DN, INPUT_PULLUP);
58
+
}
59
+
60
+
voidcheckInputs(){
61
+
checkRot();
62
+
}
63
+
64
+
bool rotVel = 0; //high velocity setting (x10 rather than x1)
65
+
unsignedlong rotLastStep = 0; //timestamp of last completed step (detent)
66
+
int rotLastVal = 0;
67
+
voidcheckRot(){
68
+
int rotCurVal = rot.read();
69
+
if(rotCurVal!=rotLastVal){ //we've sensed a state change
70
+
rotLastVal = rotCurVal;
71
+
Serial.println(rotCurVal,DEC);
72
+
if(rotCurVal>=4 || rotCurVal<=-4){ //we've completed a step of 4 states (this library doesn't seem to drop states much, so this is reasonably reliable)
73
+
unsignedlong now = millis();
74
+
if((unsignedlong)(now-rotLastStep)<=ROT_VEL_START) rotVel = 1; //kick into high velocity setting (x10)
75
+
elseif((unsignedlong)(now-rotLastStep)>=ROT_VEL_STOP) rotVel = 0; //fall into low velocity setting (x1)
0 commit comments