-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSetup.h
186 lines (138 loc) · 3.28 KB
/
Setup.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
#include "SPI.h"
#include "fonts.h"
//Encoder
#define encA PB0
#define encB PB1
#define enc2A PB10 //11
#define enc2B PB11 //10
#define BUT1 PA0
#define BUT2 PB15
#define STARTBUT PB7
#define BUTLED3 PA12
#define START PA2
#define RESET PA1
int DAC = PB6; //????
int Gate1 = PB5;
int Gate2 = PC13;
byte CV1 = 1;
byte CV2 = 0;
char Modes[] = {'P', 'L', 'N', 'O', 'M'};
char Modes2[] = {'P', 'S'};
byte Mode = 0;
byte Mode2 = 0;
int encAVal, encALast, encBVal;
int encAVal2, encALast2, encBVal2;
HardwareTimer MainTimer(1);
long ClockF = 72000000;
struct ClockStruct {
char Name[15];
long Psc = 0;
long Arr = 0;
};
struct PWMStruct{
long PWM1=1;
long PWM2=1;
long PWM1Counter=0;
long PWM2Counter=0;
boolean Phase=0;
};
ClockStruct MainClock;
PWMStruct BeatPWMS;
PWMStruct SequencePWMS;
ClockStruct SequenceClock;
const short MaxPatternLength = 16;
short Timers[MaxPatternLength] ;
short calcBeatPos[MaxPatternLength];
short BeatPos[MaxPatternLength] ;
short Notes[MaxPatternLength] ;
short Octave[MaxPatternLength] ;
short Volume[MaxPatternLength] ;
int countlength = sizeof(Notes) / sizeof(short);
const short NoteLengths[6] = {0, 1, 2, 4, 8, 16};
const float BeatLengths[6] = {0, 4, 2, 1, 0.5, 0.25};
const short NumPatterns = 7;
const int DefaultTempo=120;
int Tempo = DefaultTempo;
long BaseTime = 1000000L * (4 * 60) / Tempo;
long BeatTime = 1000000L * 60 / Tempo;
short GateLength = 4;
long SeqGateTime = BaseTime * (GateLength / 8);
long ms15 = 015000L;
const short MinTempo = 30;
const short MaxTempo = 300;
int PlaceCount = 0;
int ErasePos = -1;
int bErasePos;
int Beat = 1;
int MaxBeat = 10;
float NumberOfBeats = 1.0;
short CurrentPattern = 0;
short NextPattern = -1;
short encPos = Tempo;
short NewEncPos = Tempo;
short encPos2 = GateLength;
short NewEncPos2 = GateLength;
//float Range = 819.2; // (2^12/5)
float Range = 1365.33333; // (2^12/3)
volatile int hKey ;
volatile int hOctave;
volatile int hNote;
volatile int houtValue;
int CX = 0;
int CY = 0;
int Width = 8;
int Height = 8;
void SetupEncoders() {
pinMode(encA, INPUT);
pinMode(encB, INPUT);
pinMode(enc2A, INPUT);
pinMode(enc2B, INPUT);
//digitalWrite(encA, HIGH);
//digitalWrite(encB, HIGH);
//digitalWrite(enc2A, HIGH);
//digitalWrite(enc2B, HIGH);
}
void SetupOLED() {
_Res_Max_X = SH1106_RES_X;
_GRAM_Col_Start = SH1106_GRAM_COL_START;
_GRAM_Col_End = SH1106_GRAM_COL_END;
_GRAM_Page_Start = SH1106_GRAM_PAGE_START;
_GRAM_Page_End = SH1106_GRAM_PAGE_END;
_RAM_Pages = SH1106_GRAM_PAGE_END - SH1106_GRAM_PAGE_START + 1;
SPI.begin();
SPI.setBitOrder(MSBFIRST);
pinMode(CS_DI, OUTPUT);
pinMode(DC_DI, OUTPUT);
pinMode(RST_DI, OUTPUT);
Reset();
Cursor(0, 0);
DrawMode(NORMAL);
_FontType = Terminal_8pt;
_FontHight = Terminal_8ptFontInfo.CharacterHeight;
_FontDescriptor = Terminal_8ptFontInfo.Descriptors;
for (int x = 0; x < 128; x++) {
for (int y = 0; y < 64; y++) {
Plot(x, y);
}
Refresh();
}
DrawMode(CLEAR);
for (int x = 0; x < 128; x++) {
for (int y = 0; y < 64; y++) {
Plot(x, y);
}
Refresh();
}
Erase(0, 0, 128, 64);
Refresh();
}
void SetupDacs() {
SPI.begin();
SPI.setBitOrder(MSBFIRST);
pinMode(DAC, OUTPUT);
digitalWrite(DAC, HIGH);
}
void SetupGates() {
pinMode(Gate2, OUTPUT);
pinMode(Gate1, OUTPUT);
}