hello
i am in the process of building a wooden crank for winding on a video file - a bit like controlling the playhead of the video file but just having a big wooden handle for it (this will be attached to a pair of rollers across which the video will be wound on). I bought a simple rotary encoder with a fairly low resolution but it will do. it counts from 0 to 255 which is great because the way i plan to control the video is through a program called Modul8 and using midi. the playhead is a variable parameter in modul8 that can be mapped to a midi CC value.
I have been playing aroudn with some code I found and bits i have written before, and at the moment the code outputs a count and i can see that it is sending it over MIDI (my midi to usb interface shows an led pulse that matches the rate at which i turn the encoder) however i am not actually receiving any midi into my computer. does anyone have any suggestions of where i might be going wrong?
all help is greatly appreciated
/* 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 as 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 will be changed by 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);
}