Here is a posting of more unfinished but working code of a Danger Shield midi control surface for Linux that I'm making using ttymidi. Was changing pitch & other effect values in TerminatorX I was also scratching loops with the sliders... Feedback would be great..
// Danger Board v1.0 ttymidi MIDI-through-USB for
// linux using the Danger Shield v1.0
// By: Brian Lightfoot (brianlightfoot@gmail.com)
// More info: http://make.nycresistor.com/ds-1.0
// http://www.varal.org/ttymidi/
//our setup stuff
#include "_init.h"
//ttymidi include
#include <ardumidi.h>
void setup()
{
ds_init();
}
// setup our varables here
int modecount = 0;
int note_on = 0;
int seg = 255;
int slider1_value = 0;
byte slider2_value = 0;
byte slider3_value = 0;
boolean button1_state = false;
boolean button2_state = false;
boolean button3_state = false;
boolean last_button1_state = false;
boolean last_button2_state = false;
boolean last_button3_state = false;
void loop()
{
//in this while loop we have instrument mode
while(modecount == 0)
{
// Show mode on 7-segment
// change this to usefull output in the future int seg above is value
digitalWrite(LATCH_PIN, 0);
shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, seg);
digitalWrite(LATCH_PIN, 1);
//read all our slider values & button states.
slider1_value = analogRead(SLIDER1_PIN) * 17;
slider2_value = analogRead(SLIDER2_PIN) / 8;
slider3_value = analogRead(SLIDER3_PIN) / 8;
button1_state = digitalRead(BUTTON1_PIN);
button2_state = digitalRead(BUTTON2_PIN);
button3_state = digitalRead(BUTTON3_PIN);
//Play note if button is pressed slider3 is value of note slider to is velocity of note
if (button1_state && !last_button1_state)
{
delay(100);
midi_note_on(0, slider3_value, slider2_value);
note_on = 1;
}
// turn of note if slider3 was moved must hold button down and sweep slider3 back across
// to turn note off
if (button2_state && !last_button2_state)
{
// turn off notes when slider pot is in same position or when sweeped back
//across value need to change this.... to somthing more functional
midi_note_off(0, slider3_value, slider2_value);
note_on = 0;
}
//Change the mode if button 3 pressed break the while loop
if (button3_state && !last_button3_state)
{
modecount++;
}
//write values directly to our leds for led brightness.
analogWrite(SLIDER1_LED_PIN, slider1_value);
analogWrite(SLIDER2_LED_PIN, slider2_value);
analogWrite(SLIDER3_LED_PIN, slider3_value);
}
// this while loop is controller mode
while(modecount == 1) {
//read all our slider values & button states.
slider1_value = analogRead(SLIDER1_PIN) * 17;
slider2_value = analogRead(SLIDER2_PIN) / 8;
slider3_value = analogRead(SLIDER3_PIN) / 8;
button1_state = digitalRead(BUTTON1_PIN);
button2_state = digitalRead(BUTTON2_PIN);
button3_state = digitalRead(BUTTON3_PIN);
seg = 254;
digitalWrite(LATCH_PIN, 0);
shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, slider3_value);
digitalWrite(LATCH_PIN, 1);
if (button1_state && !last_button1_state)
//slider 3 controls the byte for what controller is used this is going to change to a button press in the near future just testing code here :D
//slider 2 controls the value of the control used
{
midi_controller_change(0, slider3_value, slider2_value);
note_on = 1;
}
//Change the mode if button 3 pressed break the while loop
if (button3_state && !last_button3_state)
{
modecount--;
}
analogWrite(SLIDER1_LED_PIN, slider1_value);
analogWrite(SLIDER2_LED_PIN, slider2_value);
analogWrite(SLIDER3_LED_PIN, slider3_value);
}
}