Browse Source

clear rep

master
Lukas 11 years ago
parent
commit
22ffaf6e00
  1. 42
      sketches/testing/_4051_test.ino
  2. 92
      sketches/testing/midi_in_out_softwareserial.ino

42
sketches/testing/_4051_test.ino

@ -1,42 +0,0 @@
int tolerance = 4;
const int s0 = 10;
const int s1 = 9;
const int s2 = 8;
int pots[] = {-1,-1};
void setup() {
Serial.begin(9600);
pinMode(s0,OUTPUT);
pinMode(s1,OUTPUT);
pinMode(s2,OUTPUT);
}
void loop() {
//get Y0 of 4051
digitalWrite(s0, LOW);
digitalWrite(s1, LOW);
digitalWrite(s1, LOW);
int read = analogRead(A1);
//only print value on change (tolerance of 4 out of 1024)
if (pots[0] < read - tolerance || pots[0] > read + tolerance) {
pots[0] = read;
Serial.print("pot 0: ");
//print value between 0 & 127 like MIDI velocity ;)
Serial.print(pots[0]/8);
Serial.println();
}
//get Y1 of 4051, analog to Y0
digitalWrite(s0, HIGH);
digitalWrite(s1, LOW);
digitalWrite(s1, LOW);
read = analogRead(A1);
if (pots[1] < read - tolerance || pots[1] > read + tolerance) {
pots[1] = read;
Serial.print("pot 1: ");
Serial.print(pots[1]/8);
Serial.println();
}
}

92
sketches/testing/midi_in_out_softwareserial.ino

@ -1,92 +0,0 @@
#include <SoftwareSerial.h>
// RX, TX for MIDI out
SoftwareSerial MIDI(10, 11);
//button pin
const int switchPin = 6;
//rotary encoder pins
const int encAPin = 4;
const int encBPin = 5;
//for sending note-off once after button is released
boolean btnOff = false;
//old rotary encoder value
int encA = LOW;
//read rotary encoder value
int enc = HIGH;
void setup()
{
//printing baudrate
Serial.begin(9600);
//MIDI baudrate for software serial (pin 10 & 11)
MIDI.begin(31250);
//button and encoder pins as input
pinMode(switchPin, INPUT);
pinMode(encAPin, INPUT);
pinMode(encBPin, INPUT);
//activate pullup-resistors (read value is inverted, so LOW is active)
digitalWrite(switchPin, HIGH);
digitalWrite(encAPin, HIGH);
digitalWrite(encBPin, HIGH);
}
void loop()
{
//print incoming bytes on softwareserial, just for checking MIDI-in, worked
if (MIDI.available())
Serial.println(MIDI.read());
//check if button is pressed
if (digitalRead(switchPin) == LOW)
{
if (!btnOff) {
//send note on
midiSignal(144,60,100);
btnOff = true;
}
}
if (digitalRead(switchPin) == HIGH)
{
//send note off
if (btnOff) {
midiSignal(128,60,0);
btnOff = false;
}
}
//read encoder pin A
enc = digitalRead(encAPin);
//check if rotary encoder is turned
if ((encA == HIGH) && (enc == LOW)) {
//check direction of turning
if (digitalRead(encBPin) == HIGH) {
//send note on and note off directly, so signal is send on every turn
midiSignal(144,62,100);
midiSignal(128,62,100);
} else {
//other direction, other note value
midiSignal(144,61,100);
midiSignal(128,61,100);
}
}
//save "old" encoder value
encA = enc;
}
//send MIDI signal through softwareserial
void midiSignal(byte b1, byte b2, byte b3) {
//debug printing
Serial.print("send: ");
Serial.print(b1);
Serial.print(" | ");
Serial.print(b2);
Serial.print(" | ");
Serial.print(b3);
Serial.println("");
MIDI.write(b1);
MIDI.write(b2);
MIDI.write(b2);
}
Loading…
Cancel
Save