help with rotary shaft encoder midi input
hello
i in process of building wooden crank winding on video file - bit controlling playhead of video file having big wooden handle (this attached pair of rollers across video wound on). bought simple rotary encoder low resolution do. counts 0 255 great because way plan control video through program called modul8 , using midi. playhead variable parameter in modul8 can mapped midi cc value.
i have been playing aroudn code found , bits have written before, , @ moment code outputs count , can see sending on midi (my midi usb interface shows led pulse matches rate @ turn encoder) not receiving midi computer. have suggestions of might going wrong?
all appreciated
i in process of building wooden crank winding on video file - bit controlling playhead of video file having big wooden handle (this attached pair of rollers across video wound on). bought simple rotary encoder low resolution do. counts 0 255 great because way plan control video through program called modul8 , using midi. playhead variable parameter in modul8 can mapped midi cc value.
i have been playing aroudn code found , bits have written before, , @ moment code outputs count , can see sending on midi (my midi usb interface shows led pulse matches rate @ turn encoder) not receiving midi computer. have suggestions of might going wrong?
all appreciated
code: [select]
/* rotary encoder read example */
#define enc_a 14
#define enc_b 15
#define enc_port pinc
byte printing_byte = 0;
byte incomingbyte;
byte note;
byte velocity;
int pot;
byte byte1;
byte byte2;
byte byte3;
void setup()
{
/* setup encoder pins inputs */
pinmode(enc_a, input);
digitalwrite(enc_a, high);
pinmode(enc_b, input);
digitalwrite(enc_b, high);
serial.begin (31250);
}
void loop()
{
static uint8_t counter = 0; //this variable changed encoder input
int8_t tmpdata;
/**/
tmpdata = read_encoder();
if( tmpdata ) {
serial.print("counter value: ");
serial.println(counter, dec);
counter += tmpdata;
}
}
/* returns change in encoder state (-1,0,1) */
int8_t read_encoder()
{
int8_t enc_states[] = {0,-1,1,0,1,0,0,-1,-1,0,0,1,0,1,-1,0};
static uint8_t old_ab = 0;
/**/
old_ab <<= 2; //remember previous state
old_ab |= ( enc_port & 0x03 ); //add current state
return ( enc_states[( old_ab & 0x0f )]);
int8_t tmpdata;
tmpdata = read_encoder();
printing_byte = map(tmpdata, 128, 255, 0, 127);{
midi_send(0xb0, 7, printing_byte);
}
}
void midi_send(byte cmd, byte data1, byte data2) {
serial.print(cmd, byte);
serial.print(data1, byte);
serial.print(data2, byte);
}
never mind - managed work - sending information on serial.
code: [select]
/* rotary encoder read example */
#define enc_a 14
#define enc_b 15
#define enc_port pinc
byte printing_byte = 0;
byte incomingbyte;
byte note;
byte velocity;
int pot;
byte byte1;
byte byte2;
byte byte3;
void setup()
{
/* setup encoder pins inputs */
pinmode(enc_a, input);
digitalwrite(enc_a, high);
pinmode(enc_b, input);
digitalwrite(enc_b, high);
serial.begin (31250);
}
void loop()
{
static uint8_t counter = 0; //this variable changed encoder input
int8_t tmpdata;
/**/
tmpdata = read_encoder();
if( tmpdata ) {
counter += tmpdata;
printing_byte = map(counter, 0, 1020, 0, 127);
midi_send(0xb0, 7, printing_byte);
}
}
/* returns change in encoder state (-1,0,1) */
int8_t read_encoder()
{
int8_t enc_states[] = {0,-1,1,0,1,0,0,-1,-1,0,0,1,0,1,-1,0};
static uint8_t old_ab = 0;
/**/
old_ab <<= 2; //remember previous state
old_ab |= ( enc_port & 0x03 ); //add current state
return ( enc_states[( old_ab & 0x0f )]);
int8_t tmpdata;
}
void midi_send(byte cmd, byte data1, byte data2) {
serial.print(cmd, byte);
serial.print(data1, byte);
serial.print(data2, byte);
}
Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > help with rotary shaft encoder midi input
arduino
Comments
Post a Comment