forked from raszhivin/arpeggiator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
arpeggiator.ino
113 lines (93 loc) · 2.57 KB
/
arpeggiator.ino
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
#include <TimerOne.h>
#include "engine.h"
arp a(C, 5, 2, 6, 200, c_harmonic, 0);
bool button_pressed;
int ButtonVal;
int ButtonClicks;
int latchMode;
// A6 = baseNotepin ROOT
// A5 = baseOctavepin TONIC
// A4 = octaveShiftpin PROGR.
// A3 = modepin MODE
// A2 = indelaypin TEMPO
// A1 = orderpin ORDER
// A0 = stepspin STEPS
#define latchPin 4
#define baseNotepin 6
#define baseOctavepin 5
#define octaveShiftpin 4
#define modepin 3
#define indelaypin 2
#define orderpin 1
#define stepspin 0
#define LEDPin 5
// Synchronization: choose one of two possible options:
//#define EXT_SYNC // korg synx
#define INT_SYNC // pot tempo
void readPoties()
{
unsigned i;
a.setupArp(analogRead(baseNotepin), analogRead(baseOctavepin), analogRead(octaveShiftpin), analogRead(stepspin), analogRead(indelaypin), analogRead(orderpin), analogRead(modepin));
// latch slide switch is connected to D4
latchMode = digitalRead(latchPin);
// play buttons are connected to pins D6-D12
for (i=12;i>5;i--)
if (!(digitalRead(i))) {
button_pressed = true; ButtonVal = 13-i;
if (ButtonVal == 1) { // reverse button order
ButtonVal = 7;
ButtonClicks = (ButtonClicks+1);
} else if (ButtonVal == 2) {
ButtonVal = 6;
ButtonClicks = 0;
} else if (ButtonVal == 3) {
ButtonVal = 5;
ButtonClicks = 0;
} else if (ButtonVal == 4) {
ButtonVal = 4;
ButtonClicks = 0;
} else if (ButtonVal == 5) {
ButtonVal = 3;
ButtonClicks = 0;
} else if (ButtonVal == 6) {
ButtonVal = 2;
ButtonClicks = 0;
} else if (ButtonVal == 7) {
ButtonVal = 1;
ButtonClicks = 0;
}
return;
}
}
void setup()
{
a.midibegin();
Timer1.initialize(200000); // initialize timer1, and set a 1/10 second period
Timer1.attachInterrupt(readPoties); // We will read potis and buttons values within timer interrupt
// LED pin
pinMode(LEDPin, OUTPUT);
// Initialize pins for 2-pins pushbuttons with pullup enabled
for (unsigned i=6;i<13;i++)
{
pinMode(i,INPUT_PULLUP);
}
pinMode(latchPin,INPUT_PULLUP);
button_pressed = false;
ButtonVal = 1;
ButtonClicks = 0;
}
void loop()
{
if (button_pressed)
{
a.setProgression(ButtonVal-1);
if(latchMode == LOW ){
//if((ButtonVal == 7) && (ButtonClicks > 2)){
button_pressed = false;
ButtonClicks = 0;
}
digitalWrite(LEDPin, HIGH);
a.play();
digitalWrite(LEDPin, LOW);
}
}