Skip to content

Commit 13438ae

Browse files
authored
Add files via upload
0 parents  commit 13438ae

File tree

1 file changed

+122
-0
lines changed

1 file changed

+122
-0
lines changed

SL1200_MIDIFader.ino

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
//
2+
// SL-1200mkII USBMIDI Fader
3+
// by spinn.teramoto (Akihabara Housing, Ltd.) 2021
4+
//
5+
// note: Pitch fader of SL-1200 mkII is "A Curve" potentiometer.
6+
// So it need to be converted to "B Curve"
7+
//
8+
// 0 833 1023
9+
// |------------------+-------------------| :Original Scale (A curve(Log))
10+
//
11+
// 0 64 127
12+
// |------------------+-------------------| :Converted Scale (B curve(Linear))
13+
//
14+
15+
#include "MIDIUSB.h" // include MIDIUSB library
16+
17+
const int FADER = A0; // Pitch Fader pin
18+
const int LED = 12; // Center LED pin
19+
const int SWITCH1 = 3; // Deck A selector pin
20+
const int SWITCH2 = 5; // Deck B selector pin
21+
22+
23+
int analogval =0; // original fader val (0-1023)
24+
float s0 = 0; // Internal val for curve conversion
25+
float s1 = 0; // Internal val for curve conversion
26+
float adjustval = 2.4287; // Log((1023-833/1023), 0.5), "833" is original fader value of center position
27+
int faderval = 0; // Pitch Fader Val (0-127)
28+
int faderval_old =0; // Fader Val Old
29+
30+
int switchval_1 = 0; // Switch 1 value
31+
int switchval_1_old = 0; // Switch 1 value old
32+
int switchval_2 = 0; // Switch 2 value
33+
int switchval_2_old = 0; // Switch 2 value old
34+
35+
int val0= 0; // Internal val for Fader
36+
int val1= 0; // Internal val for Switch 1
37+
int val2= 0; // Internal val for Switch 2
38+
39+
40+
void setup()
41+
{
42+
pinMode(LED, OUTPUT);
43+
pinMode(SWITCH1, INPUT_PULLUP); // Connecting Toggle Switch with pullup mode
44+
pinMode(SWITCH2, INPUT_PULLUP); //
45+
Serial.begin(9600);
46+
}
47+
48+
void noteOn(byte channel, byte pitch, byte velocity) {
49+
midiEventPacket_t noteOn = {0x09, 0x90 | channel, pitch, velocity};
50+
MidiUSB.sendMIDI(noteOn);
51+
}
52+
53+
void noteOff(byte channel, byte pitch, byte velocity) {
54+
midiEventPacket_t noteOff = {0x08, 0x80 | channel, pitch, velocity};
55+
MidiUSB.sendMIDI(noteOff);
56+
}
57+
58+
void controlChange(byte channel, byte control, byte value) {
59+
midiEventPacket_t event = {0x0B, 0xB0 | channel, control, value};
60+
MidiUSB.sendMIDI(event);
61+
}
62+
63+
64+
void loop()
65+
{
66+
67+
//////// Pitch Fader
68+
69+
// Calculating fader value
70+
int analogval = analogRead(FADER); // Read fader value
71+
float s0 = (float)(1023 - analogval)/1023.0; // Convert A curve to B curve
72+
float s1 = pow(s0,1.0/adjustval);
73+
int faderval = 127 - int(s1*127); // Set Fader value in B curve scale
74+
75+
// Light LED up when fader position is middle
76+
if ( faderval >63 && faderval <65 ) {
77+
digitalWrite( LED, HIGH );
78+
} else {
79+
digitalWrite( LED, LOW );
80+
}
81+
82+
// sending control change
83+
int val0 = faderval - faderval_old;
84+
if ( not( val0 == 0 )) {
85+
controlChange(5, 16, faderval); // Channel 6, Control Change 016, Fader value
86+
MidiUSB.flush();
87+
}
88+
faderval_old = faderval;
89+
90+
91+
/////// Deck Selector
92+
93+
// Reading Switch Value
94+
int switchval_1 = digitalRead(SWITCH1);
95+
int switchval_2 = digitalRead(SWITCH2);
96+
97+
// Sending note by Switch 1
98+
int val1 = switchval_1 - switchval_1_old;
99+
if ( not(val1 == 0) ) {
100+
if ( switchval_1 == 1 ) {
101+
noteOn(5, 48, 64); // Channel 6, C3, normal velocity
102+
MidiUSB.flush();
103+
delay(500);
104+
noteOff(5, 48, 64); // Channel 6, C3, normal velocity
105+
MidiUSB.flush();
106+
}
107+
switchval_1_old = switchval_1;
108+
}
109+
110+
// Sending note by Switch 2
111+
int val2 = switchval_2 - switchval_2_old;
112+
if ( not(val2 == 0) ) {
113+
if ( switchval_2 == 1 ) {
114+
noteOn(5, 50, 64); // Channel 6, D3, normal velocity
115+
MidiUSB.flush();
116+
delay(500);
117+
noteOff(5, 50, 64); // Channel 6, D3, normal velocity
118+
MidiUSB.flush();
119+
}
120+
switchval_2_old = switchval_2;
121+
}
122+
}

0 commit comments

Comments
 (0)