Skip to content
Permalink
Browse files

find out which col and row we are in

  • Loading branch information...
J0J0 T
J0J0 T committed Nov 12, 2018
1 parent e61bf0b commit 649d310613c5f7053b0462e370348ab6383cd295
Showing with 22 additions and 26 deletions.
  1. +22 −26 matrixmidi.ino
@@ -10,32 +10,26 @@ const uint8_t ledPin = 13; // LED pin on most Arduino

const uint8_t outPins[] = {6,7,8}; // the rows
const uint8_t inPins[] = {9,10,11,12}; // the columns
const uint8_t rowChars[][3] = {
const uint8_t buttons[][3] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'},
};

uint8_t inVal0 = 0;
uint8_t inVal1 = 0;
uint8_t inVal2 = 0;
uint8_t inVal3 = 0;
uint8_t pinToTest = 0; // initialize variable for row test blink

void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(outPins[0], OUTPUT); // our output line for col 0 (1,4,7,*)
pinMode(outPins[1], OUTPUT); // col 1 (2,5,8,0)
pinMode(outPins[2], OUTPUT); // col 2 (3,6,9,#)
pinMode(inPins[0], INPUT); // just for clarity, INPUT is the default mode anyway
pinMode(inPins[1], INPUT); // just for clarity, INPUT is the default mode anyway
pinMode(inPins[2], INPUT); // just for clarity, INPUT is the default mode anyway
pinMode(inPins[3], INPUT); // just for clarity, INPUT is the default mode anyway
digitalWrite(outPins[0], LOW); // set HIGH to check col 0
digitalWrite(outPins[1], LOW); // set HIGH to check col 1
digitalWrite(outPins[2], HIGH); // set HIGH to check col 2
pinMode(inPins[1], INPUT);
pinMode(inPins[2], INPUT);
pinMode(inPins[3], INPUT);
digitalWrite(outPins[0], LOW); // initialize cols with LOW
digitalWrite(outPins[1], LOW);
digitalWrite(outPins[2], LOW);
USBserial.begin(115200); // debugging settings start here
aSerial.setPrinter(USBserial);
aSerial.setFilter(VERBOSITY);
@@ -44,19 +38,21 @@ void setup()

void loop()
{
inVal0 = digitalRead(inPins[0]);
inVal1 = digitalRead(inPins[1]);
inVal2 = digitalRead(inPins[2]);
inVal3 = digitalRead(inPins[3]);
aSerial.vvv().p("inPin 0 value: ").pln(inVal0);
aSerial.vvv().p("inPin 1 value: ").pln(inVal1);
aSerial.vvv().p("inPin 2 value: ").pln(inVal2);
aSerial.vvv().p("inPin 3 value: ").pln(inVal3);
aSerial.vvv().pln();
pinToTest = digitalRead(inPins[3]); // which button row should be tested
if (pinToTest == HIGH) { // blink led if pinToTest on _row_ 0 is pressed)
digitalWrite(ledPin, HIGH);
for (int col = 0; col < sizeof(outPins); col++)
{
digitalWrite(outPins[col], HIGH);
for (int row = 0; row < sizeof(inPins); row++)
{
if (digitalRead(inPins[row]) == HIGH) // blink led if inPin is HIGH)
{
digitalWrite(ledPin, HIGH);
aSerial.vvv().p("yes, it's high: ").p(col).p(" ").pln(row);
aSerial.vvv().pln();
}
}
digitalWrite(outPins[col], LOW);
aSerial.vvv().pln();
}
delay(500);
delay(500); // enable for slower debugging, otherwise lit led can't be seen ;-)
digitalWrite(ledPin, LOW);
}

0 comments on commit 649d310

Please sign in to comment.
You can’t perform that action at this time.