-
Notifications
You must be signed in to change notification settings - Fork 12
/
mg2HW.h
359 lines (247 loc) · 5.69 KB
/
mg2HW.h
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
/*
mg2HW.cpp library
this library is to be used with standuino MicroGranny hardware
MOZZI library compatible
documentation of the library you find here:
mg2HW library
Created by Vaclav Pelousek 2013 www.pelousek.eu
for Standuino wwww.standuino.eu
*/
#ifndef mg2HW_h
#define mg2HW_h
#include "Arduino.h"
#include <avr/pgmspace.h>
#include <shiftRegisterFast.h>
#include <portManipulations.h>
#define DEFAULT 0
#define UNFREEZE_EXTERNALY 1
#define NUMBER_OF_ROWS 6
#define BUTTON_ROW 6
//
#define LATCH_PIN 9
#define CLOCK_PIN 8
#define DATA_PIN 19
#define BUTTON_PIN 6
#define BUTTON_2_PIN 7
#define LED_PIN 6 //2
#define LED_2_PIN 7
#define LED_ROW 4
#define LED_2_ROW 5
#define DIGIT_1_PIN 5
#define DIGIT_2_PIN 2
#define DIGIT_3_PIN 3
#define DIGIT_4_PIN 4 //6
#define BIG_1 0
#define BIG_2 3
#define BIG_3 4
#define BIG_4 5
#define BIG_5 6
#define BIG_6 7
#define NUMBER_OF_BIG_BUTTONS 6
#define FN 11
#define PAGE 8
#define UP 10
#define DOWN 9
#define REC 2
#define HOLD 1
#define SEG_A 5 //Display pin 14
#define SEG_B 7 //Display pin 16
#define SEG_C 3 //Display pin 13
#define SEG_D 1 //Display pin 3
#define SEG_E 2 //Display pin 5
#define SEG_F 6 //Display pin 11
#define SEG_G 4 //Display pin 15
#define SEG_DOT 0
#define LED_R_PIN 9
#define LED_G_PIN 8
#define LED_B_PIN 10
#define KNOB_LED_1_PIN 15 //5
#define KNOB_LED_2_PIN 14 //2
#define KNOB_LED_3_PIN 13 //3
#define KNOB_LED_4_PIN 12 //6
#define KNOB_LED_1 15
#define KNOB_LED_2 14
#define KNOB_LED_3 13
#define KNOB_LED_4 12
#define KNOB_PIN_1 4
#define KNOB_PIN_2 3
#define KNOB_PIN_3 2
#define KNOB_PIN_4 1
//
/*
//
#define LATCH_PIN 8
#define CLOCK_PIN 19
#define DATA_PIN 9
#define BUTTON_PIN 6
#define BUTTON_2_PIN 7
#define LED_PIN 2
#define LED_2_PIN 7
#define LED_ROW 4
#define LED_2_ROW 5
#define DIGIT_1_PIN 5
#define DIGIT_2_PIN 4
#define DIGIT_3_PIN 3
#define DIGIT_4_PIN 6
#define KNOB_PIN_1 1
#define KNOB_PIN_2 2
#define KNOB_PIN_3 3
#define KNOB_PIN_4 4
#define LED_R_PIN 9
#define LED_G_PIN 12
#define LED_B_PIN 8
#define KNOB_LED_1_PIN 13 //5
#define KNOB_LED_2_PIN 10 //2
#define KNOB_LED_3_PIN 11 //3
#define KNOB_LED_4_PIN 14 //6
#define KNOB_LED_1 13
#define KNOB_LED_2 10
#define KNOB_LED_3 11
#define KNOB_LED_4 14
#define SEG_A 7 //Display pin 14
#define SEG_B 5 //Display pin 16
#define SEG_C 1 //Display pin 13
#define SEG_D 3 //Display pin 3
#define SEG_E 4 //Display pin 5
#define SEG_F 6 //Display pin 11
#define SEG_G 0 //Display pin 15
#define SEG_DOT 2
#define BIG_1 2
#define BIG_2 3
#define BIG_3 6
#define BIG_4 4
#define BIG_5 1
#define BIG_6 7
#define NUMBER_OF_BIG_BUTTONS 6
#define FN 8
#define PAGE 15
#define UP 9
#define DOWN 12
#define REC 0
#define HOLD 5
//
*/
const unsigned char bigButton[NUMBER_OF_BIG_BUTTONS]={BIG_1,BIG_2,BIG_3,BIG_4,BIG_5,BIG_6};
#define KNOB_TOLERANCE 20
#define KNOB_FREEZE_DISTANCE 128
#define NUMBER_OF_KNOBS 4
#define NUMBER_OF_BUTTONS 16
#define NUMBER_OF_DIGITS 4
#define XXX 9
#define IND 12
#define INT 15
#define PAR 18
#define DIR 21
#define PCH 24
#define CRS 27
#define STR 30
#define CTT 33
#define SHF 36
#define LOP 39
#define RTE 42
#define AMT 45
#define ONN 48
#define OFF 51
#define FWD 54
#define BCK 57
#define RD1 60
#define RD2 63
#define PRE 66
#define SEL 69
#define ND 72
#define ST 75
#define REP 78
#define DIR 81
#define LFO 84
#define VOL 87
#define COP 90
#define SVE 93
#define SVD 96
#define LPS 99
#define LPE 102
#define CPD 105
#define PST 108
#define CLR 111
#define FACTORY_CLEAR_PIN 2
#define FACTORY_CLEAR_SIGNAL_PIN 13
#define VOID 36
#define MINUS 37
#define LINES 38
#define SLASH 39
#define ZERO 0
const unsigned char knobLed[NUMBER_OF_KNOBS]={KNOB_LED_1_PIN,KNOB_LED_2_PIN,KNOB_LED_3_PIN,KNOB_LED_4_PIN};
#define LED_R 9
#define LED_G 12
#define LED_B 8
#define NUMBER_OF_COLORS 8
#define BLACK 0
#define RED 1
#define GREEN 2
#define BLUE 3
#define YELLOW 4
#define MAGENTA 5
#define CIAN 6
#define WHITE 7
/*
Segments
- A
F / / B
- G
E / / C
- D
*/
class mg2HW
{
public:
mg2HW(); // constructor
void initialize();
void update();
//void updateButtons();
void dimForRecord(unsigned char _BUTTON);
void setLed(unsigned char _LED, boolean _STATE);
void setColor(unsigned char _COLOR);
boolean buttonState(unsigned char _BUTTON);
boolean justPressed(unsigned char _BUTTON);
boolean justReleased(unsigned char _BUTTON);
boolean knobFreezed(unsigned char _KNOB);
// boolean knobMoved(unsigned char _KNOB);
void freezeAllKnobs();
void unfreezeAllKnobs();
void freezeKnob(unsigned char _KNOB);
void unfreezeKnob(unsigned char _KNOB);
int knobValue(unsigned char _KNOB);
int lastKnobValue(unsigned char _KNOB);
void setLastKnobValue(unsigned char _KNOB,int _val);
// void setFreezeType(unsigned char _TYPE);
void flipSwitch(unsigned char _SWITCH);
void setSwitch(unsigned char _SWITCH, boolean _STATE);
boolean switchState(unsigned char _SWITCH);
void resetSwitches();
void displayText(char *text);
void displayChar(char whichChar,unsigned char _digit) ;
void lightNumber(int numberToDisplay, unsigned char _digit);
void displayNumber(int _number);
void setDot(unsigned char _dot, boolean _state);
unsigned char soundFromSwitches();
unsigned char soundFromButtons();
// boolean factoryClear();
// void factoryCleared();
void updateKnobs();
void updateButtons();
void updateDisplay();
int _row;
unsigned char displayBuffer[NUMBER_OF_ROWS];
private:
int buttonStateHash;
int lastButtonStateHash;
int switchStateHash;
int justPressedHash;
int justReleasedHash;
int ledStateHash;
unsigned char knobFreezedHash;
int knobValues[NUMBER_OF_KNOBS];
int lastKnobValues[NUMBER_OF_KNOBS];
boolean mozzi;
boolean unfreezeExternaly;
};
#endif