9
9
// One potentiometer to control LFO depth
10
10
// A digital input is used to re-trigger/sync the LFO
11
11
//
12
- // The LFOs output to pins 11 (LFO1) and 3 (LFO2). Since the output is PWM, it's
12
+ // The LFOs output to pins 11 (LFO1) and 3 (LFO2). Since the output is PWM, it's
13
13
// important to add low-pass filters to these pins to smooth out the resulting waveform
14
14
//
15
15
// See accompanying Fritzing documents for circuit information.
16
16
17
17
18
18
// The MIT License (MIT)
19
- //
19
+ //
20
20
// Copyright (c) 2013-2018 Robert W. Gallup (www.robertgallup.com)
21
- //
21
+ //
22
22
// Permission is hereby granted, free of charge, to any person obtaining a copy
23
23
// of this software and associated documentation files (the "Software"), to deal
24
24
// in the Software without restriction, including without limitation the rights
25
25
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
26
26
// copies of the Software, and to permit persons to whom the Software is
27
27
// furnished to do so, subject to the following conditions:
28
- //
28
+ //
29
29
// The above copyright notice and this permission notice shall be included in
30
30
// all copies or substantial portions of the Software.
31
- //
31
+ //
32
32
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33
33
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34
34
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
44
44
45
45
// Used in calculating frequency tuning word
46
46
// Create constant to to only calculate 2^32 once
47
- const unsigned long long POW2TO32 = pow(2 ,32 );
47
+ const unsigned long long POW2TO32 = pow(2 , 32 );
48
48
49
49
// Output Pins (PWM - digital pins)
50
50
// WARNING: Don't change these!
@@ -67,7 +67,7 @@ const byte LFO2_OUTPUT_PIN = 3;
67
67
#include " wave/sq256.h"
68
68
69
69
// Wave table pointers
70
- byte *waveTables[] = {sine256, ramp256, saw256, tri256, pulse8, pulse16, pulse64, sq256, noise256};
70
+ const byte *waveTables[] = {sine256, ramp256, saw256, tri256, pulse8, pulse16, pulse64, sq256, noise256};
71
71
#define NUM_WAVES (sizeof (waveTables) / sizeof (byte *))
72
72
73
73
// LFO Initial wave table numbers
@@ -107,14 +107,14 @@ byte pinState;
107
107
108
108
// SYNC variables defined for optional SYNC feature, if defined in Settings.h
109
109
#if defined(SYNC)
110
- byte lastSYNC1;
111
- #if !defined(SYNC_COMMON)
112
- byte lastSYNC2;
113
- #endif
110
+ byte lastSYNC1;
111
+ #if !defined(SYNC_COMMON)
112
+ byte lastSYNC2;
113
+ #endif
114
114
#endif
115
115
116
116
// Interrupt variables are volatile
117
- volatile byte tickCounter; // Counts interrupt "ticks". Reset every 125
117
+ volatile byte tickCounter; // Counts interrupt "ticks". Reset every 125
118
118
volatile byte fourMilliCounter; // Counter incremented every 4ms
119
119
120
120
volatile unsigned long accumulatorA; // Accumulator LFO1
@@ -134,18 +134,18 @@ void setup()
134
134
#if defined(SYNC)
135
135
// Initialize SYNC pin(s) for optional SYNC feature in Settings.h
136
136
pinMode (SYNC1_PIN, INPUT);
137
- lastSYNC1 = (HIGH== SYNC1_TRIGGER)? LOW: HIGH;
138
- #if !defined(SYNC_COMMON)
139
- pinMode (SYNC2_PIN, INPUT);
140
- lastSYNC2 = (HIGH== SYNC2_TRIGGER)? LOW: HIGH;
141
- #endif
137
+ lastSYNC1 = (HIGH == SYNC1_TRIGGER) ? LOW : HIGH;
138
+ #if !defined(SYNC_COMMON)
139
+ pinMode (SYNC2_PIN, INPUT);
140
+ lastSYNC2 = (HIGH == SYNC2_TRIGGER) ? LOW : HIGH;
141
+ #endif
142
142
#endif
143
143
144
144
#if defined(DISPLAY)
145
145
// Initialize display
146
146
displaySurface.begin ();
147
147
#endif
148
-
148
+
149
149
// Initialize PWM Pins
150
150
pinMode (LFO1_OUTPUT_PIN, OUTPUT); // pin11= PWM:A
151
151
pinMode (LFO2_OUTPUT_PIN, OUTPUT); // pin 3= PWM:B
@@ -158,12 +158,12 @@ void setup()
158
158
159
159
160
160
// Initialize wave tables
161
- LFO1_WaveTable = waveTables[0 ];
162
- LFO2_WaveTable = waveTables[0 ];
163
-
161
+ LFO1_WaveTable = (byte*) waveTables[0 ];
162
+ LFO2_WaveTable = (byte*) waveTables[0 ];
163
+
164
164
// Initialize wave switch states
165
- while (LFO1_WaveSwitch.stateDebounced ()== 0 );
166
- while (LFO2_WaveSwitch.stateDebounced ()== 0 );
165
+ while (LFO1_WaveSwitch.stateDebounced () == 0 );
166
+ while (LFO2_WaveSwitch.stateDebounced () == 0 );
167
167
168
168
// Initialize timer
169
169
Setup_timer2 ();
@@ -173,8 +173,8 @@ void setup()
173
173
174
174
void loop ()
175
175
{
176
-
177
- // SYNC code included if SYNC option defined in Settings.h
176
+
177
+ // SYNC code included if SYNC option defined in Settings.h
178
178
#if defined(SYNC)
179
179
180
180
// SYNC 1 + SYNC_COMMON
@@ -183,39 +183,39 @@ void loop()
183
183
lastSYNC1 = pinState;
184
184
if (pinState == SYNC1_TRIGGER) {
185
185
accumulatorA = 0 ;
186
- #if defined(SYNC_COMMON)
187
- accumulatorB = 0 ;
188
- #endif
186
+ #if defined(SYNC_COMMON)
187
+ accumulatorB = 0 ;
188
+ #endif
189
189
}
190
190
}
191
-
191
+
192
192
// Separate SYNC inputs processed if SYNC1 and SYNC2 pins are different
193
- #if !defined(SYNC_COMMON)
194
- // SYNC 2 (SYNC pins are separate)
195
- pinState = digitalRead (SYNC2_PIN);
196
- if (pinState != lastSYNC2) {
197
- lastSYNC2 = pinState;
198
- if (pinState == SYNC2_TRIGGER) accumulatorB = 0 ;
199
- }
200
- #endif
201
-
193
+ #if !defined(SYNC_COMMON)
194
+ // SYNC 2 (SYNC pins are separate)
195
+ pinState = digitalRead (SYNC2_PIN);
196
+ if (pinState != lastSYNC2) {
197
+ lastSYNC2 = pinState;
198
+ if (pinState == SYNC2_TRIGGER) accumulatorB = 0 ;
199
+ }
200
+ #endif
201
+
202
202
#endif
203
-
203
+
204
204
// Check controls every 1/10 second
205
205
if (fourMilliCounter > 25 ) {
206
- fourMilliCounter= 0 ;
206
+ fourMilliCounter = 0 ;
207
207
208
- // If DISPLAY defined in Settings.h
208
+ // If DISPLAY defined in Settings.h
209
209
#if defined(DISPLAY)
210
- displaySurface.update ();
210
+ displaySurface.update ();
211
211
#endif
212
212
213
213
// LFO 1 wave table switch
214
214
pinState = LFO1_WaveSwitch.stateDebounced ();
215
215
if (LFO1_WaveSwitch.changed ()) {
216
216
if (pinState == 1 ) {
217
217
LFO1_WaveTableNum = (LFO1_WaveTableNum + 1 ) % NUM_WAVES;
218
- LFO1_WaveTable = waveTables[LFO1_WaveTableNum];
218
+ LFO1_WaveTable = (byte*) waveTables[LFO1_WaveTableNum];
219
219
}
220
220
}
221
221
@@ -224,16 +224,16 @@ void loop()
224
224
if (LFO2_WaveSwitch.changed ()) {
225
225
if (pinState == 1 ) {
226
226
LFO2_WaveTableNum = (LFO2_WaveTableNum + 1 ) % NUM_WAVES;
227
- LFO2_WaveTable = waveTables[LFO2_WaveTableNum];
227
+ LFO2_WaveTable = (byte*) waveTables[LFO2_WaveTableNum];
228
228
}
229
229
}
230
230
231
231
// LFO 1 frequency/depth controls
232
- LFO1_TuningWord = POW2TO32 * (((((double )LFO1_FreqKnob.value ()* LFO1_FREQ_RANGE)/ 1024L ) + LFO1_FREQ_MIN) / clock);
232
+ LFO1_TuningWord = POW2TO32 * (((((double )LFO1_FreqKnob.value () * LFO1_FREQ_RANGE) / 1024L ) + LFO1_FREQ_MIN) / clock);
233
233
LFO1_Depth = LFO1_DepthKnob.value ();
234
234
235
235
// LFO 2 frequency/depth controls
236
- LFO2_TuningWord = POW2TO32 * (((((double )LFO2_FreqKnob.value ()* LFO2_FREQ_RANGE)/ 1024L ) + LFO2_FREQ_MIN) / clock);
236
+ LFO2_TuningWord = POW2TO32 * (((((double )LFO2_FreqKnob.value () * LFO2_FREQ_RANGE) / 1024L ) + LFO2_FREQ_MIN) / clock);
237
237
LFO2_Depth = LFO2_DepthKnob.value ();
238
238
}
239
239
@@ -261,8 +261,8 @@ void Setup_timer2() {
261
261
cbi (TCCR2B, WGM22);
262
262
263
263
// Enable interrupt
264
- sbi (TIMSK2,TOIE2);
265
-
264
+ sbi (TIMSK2, TOIE2);
265
+
266
266
}
267
267
268
268
// //////////////////////////////////////////////////////////////
@@ -275,10 +275,10 @@ ISR(TIMER2_OVF_vect) {
275
275
byte offset;
276
276
277
277
// Count every four milliseconds
278
- if (tickCounter++ == 125 ) {
278
+ if (tickCounter++ == 125 ) {
279
279
fourMilliCounter++;
280
- tickCounter= 0 ;
281
- }
280
+ tickCounter = 0 ;
281
+ }
282
282
283
283
// Sample wave table for LFO1
284
284
accumulatorA += LFO1_TuningWord;
@@ -289,5 +289,5 @@ ISR(TIMER2_OVF_vect) {
289
289
accumulatorB += LFO2_TuningWord;
290
290
offset = accumulatorB >> 24 ; // high order byte
291
291
OCR2B = (pgm_read_byte_near (LFO2_WaveTable + offset) * LFO2_Depth) / 1024L ;
292
-
292
+
293
293
}
0 commit comments