Im still very much a noob, i'm learning but I still have huge holes in my knowledge.
a link to the datasheet of the priority encoder http://www.ti.com/lit/ds/symlink/sn74ls148.pdf
I have 3 of these chained together and thus have 5 outputs from the encoders:
A0, A1, A2, GS of the second ls148 and GS of the third ls148
I have switches to ground on all the inputs of the encoders.
I am trying to build a midi controller that uses one single button (on pin 8 in my code) to trigger midi notes with the note number being determined by the output of the encoders. the switches on the encoder inputs should determine the note number.
EDIT -- Ultimately I would like to know how to make each encoder input (1-23) both select the midi note number AND trigger the note on /note off messages. Also a button on pin 8 should retrigger (apply note on) the last note number sent.
Here is the code
//https://github.com/tttapa/MIDI_controller
#include <MIDI_Controller.h>
HardwareSerialMIDI_Interface serialmidi = {Serial, MIDI_BAUD};
const uint8_t velocity = 0b1111111; // Maximum velocity (0b1111111 = 0x7F = 127)
int val;
int sixpin = 6; // gs pin of third 74148
int fivepin = 5; // gs pin of second 74148
int fourpin = 4; // A2 pin
int threepin = 3; // A1 pin
int twopin = 2; // A0 pin
// Create a new instance of the class 'Digital', called 'button', on pin 8, that sends MIDI messages with note 'val' on channel 1, with velocity 127
Digital button(8, val, 1, velocity);
void setup() //Setup //
{
pinMode(sixpin, INPUT);
pinMode(fivepin, INPUT);
pinMode(fourpin, INPUT);
pinMode(threepin, INPUT);
pinMode(twopin, INPUT);
}
void loop()
{
if (digitalRead(fourpin) == HIGH && digitalRead(threepin)== HIGH && digitalRead(twopin)== HIGH)
{val = 28;}
else if (digitalRead(fourpin) == HIGH && digitalRead(threepin)== HIGH && digitalRead(twopin)== LOW)
{val = 29;}
else if (digitalRead(fourpin) == HIGH && digitalRead(threepin)== LOW && digitalRead(twopin)== HIGH)
{val = 30;}
else if (digitalRead(fourpin) == HIGH && digitalRead(threepin)== LOW && digitalRead(twopin)== LOW)
{val = 31;}
else if (digitalRead(fourpin) == LOW && digitalRead(threepin)== HIGH && digitalRead(twopin)== HIGH)
{val = 32;}
else if (digitalRead(fourpin) == LOW && digitalRead(threepin)== HIGH && digitalRead(twopin)== LOW)
{val = 33;}
else if (digitalRead(fourpin) == LOW && digitalRead(threepin)== LOW && digitalRead(twopin)== HIGH)
{val = 34;}
else if (digitalRead(fourpin) == LOW && digitalRead(threepin)== LOW && digitalRead(twopin)== LOW)
{val = 35;}
if (digitalRead(fivepin) == LOW)
{val = val + 8;}
if (digitalRead(sixpin) == LOW)
{val = val + 16;}
MIDI_Controller.refresh();
}
In this line - Digital button(8, val, 1, velocity); - I can see that 'val' is 0 when creating the button instance and it does not see the changes to 'val' that happen in the loop. How can I make the changing values of 'val' apply to the Digital button?
Thanks