1
1
// #include <EEPROM.h>
2
- // #include <Wire.h>
3
- // #include <RTClib.h>
4
- // RTC_DS1307 rtc;
5
- #include < Encoder .h> // https://www.pjrc.com/teensy/td_libs_Encoder.html
6
-
7
- Encoder mainRot (A1,A0);
8
- const byte rotCount = 4 ; // values per detent. We will set each encoder to a "resting" value of rotCount, and sense moves between detents when the rot value reaches 0 (left) or rotCount*2 (right).
9
- byte mainRotLast = - 999 ;
2
+ #include < Wire.h>
3
+ #include < RTClib.h>
4
+ RTC_DS1307 rtc;
5
+ #include < ooPinChangeInt .h>
6
+ # include < AdaEncoder.h >
7
+
8
+ AdaEncoder mainRot = AdaEncoder( ' a ' ,A1,A0);
9
+
10
10
word val = 500 ;
11
11
12
12
// Display formatting
@@ -36,14 +36,14 @@ void decToBin(bool binVal[], byte i);
36
36
// //////// Main code control //////////
37
37
38
38
void setup (){
39
- // Serial.begin(57600);
40
- // Wire.begin();
41
- // rtc.begin();
42
- // if(!rtc.isrunning()) rtc.adjust(DateTime(2017,1,1,0,0,0)); //TODO test
39
+ Serial.begin (57600 );
40
+ Wire.begin ();
41
+ rtc.begin ();
42
+ if (!rtc.isrunning ()) rtc.adjust (DateTime (2017 ,1 ,1 ,0 ,0 ,0 )); // TODO test
43
43
initOutputs ();
44
44
initInputs ();
45
45
46
- mainRot.write (rotCount);
46
+ // mainRot.write(rotCount);
47
47
48
48
editDisplay (val,0 ,3 ,false );
49
49
@@ -54,26 +54,11 @@ void setup(){
54
54
55
55
void loop (){
56
56
// Things done every "clock cycle"
57
- // checkRTC(); //if clock has ticked, decrement timer if running, and updateDisplay
58
- // checkInputs(); //if inputs have changed, this will do things + updateDisplay as needed
57
+ checkRTC (); // if clock has ticked, decrement timer if running, and updateDisplay
58
+ checkInputs (); // if inputs have changed, this will do things + updateDisplay as needed
59
+
60
+ // long mainRotNew = mainRot.read();
59
61
60
- long mainRotNew = mainRot.read ();
61
- if (mainRotNew != mainRotLast){
62
- if (mainRotNew <= 0 ) { // down one detent
63
- val--;
64
- editDisplay (val,0 ,3 ,false );
65
- mainRotLast = rotCount;
66
- mainRot.write (rotCount);
67
- } else if (mainRotNew >= rotCount*2 ) {
68
- val++;
69
- editDisplay (val,0 ,3 ,false );
70
- mainRotLast = rotCount;
71
- mainRot.write (rotCount);
72
- } else {
73
- mainRotLast = mainRotNew;
74
- }
75
- editDisplay (mainRotLast,4 ,5 ,false );
76
- }
77
62
78
63
// doSetHold(); //if inputs have been held, this will do more things + updateDisplay as needed
79
64
cycleDisplay (); // keeps the display hardware multiplexing cycle going
@@ -97,6 +82,36 @@ void initInputs(){
97
82
// if(altAdjType==2) checkRot(altAdjA,altAdjB,altRotLast,false);
98
83
}
99
84
85
+ void checkInputs (){
86
+ AdaEncoder *thisEncoder=NULL ;
87
+ thisEncoder = AdaEncoder::genie ();
88
+ if (thisEncoder!=NULL ) {
89
+ int8_t clicks = thisEncoder->query ();
90
+ Serial.print (thisEncoder->getID ()); Serial.print (' :' ); Serial.println (clicks);
91
+ // editDisplay(clicks,4,5,false);
92
+ // thisEncoder->getID();
93
+ val += clicks;
94
+ editDisplay (val,0 ,3 ,false );
95
+ }
96
+ }
97
+
98
+ // //////// Clock ticking and timed event triggering //////////
99
+ unsigned long rtcPollLast = 0 ; // maybe don't poll the RTC every loop? would that be good?
100
+ byte rtcSecLast = 61 ;
101
+ void checkRTC (){
102
+ // Checks for new time-of-day second; decrements timer; checks for timed events;
103
+ // updates display for running time or date.
104
+ if (rtcPollLast<millis ()+50 ) { // check every 1/20th of a second
105
+ rtcPollLast=millis ();
106
+ // Check for timeouts based on millis
107
+ // Update things based on RTC
108
+ DateTime now = rtc.now ();
109
+ if (rtcSecLast != now.second ()) {
110
+ editDisplay (now.second (), 4 , 5 , true ); // seconds
111
+ }
112
+ }
113
+ }
114
+
100
115
void editDisplay (word n, byte posStart, byte posEnd, bool leadingZeros){
101
116
// Splits n into digits, sets them into displayNext in places posSt-posEnd (inclusive), with or without leading zeros
102
117
// If there are blank places (on the left of a non-leading-zero number), uses value 15 to blank tube
0 commit comments