Automatic Drawer Searcher (Error)

Hello everyone, thank you for you time to. I have some issue with my LEDs output I use 74154 to leds matrix y-axis and 74138 to leds matrix x-axis and 7404 inversor. I connect the leds with IDE cable which 5-horizontal and 5-vertical. My master arduino successful make connection with my slave.But I send ax01y01(I use this char to indicate row and column) to my slave but it read ax01y0. Missing the char 3. Futhermore the LEDs is not light. I hope someone can help me. Your help will be helpful to me. I attach my master, slave coding and my diargram :slight_smile:

Master code:

// Master Code
#include <Wire.h>
byte nChar =0;
char input[7];

void setup () {

  Serial.begin(9600);
  Wire.begin();
}

void loop()
{
  if (nChar < 7) {if (Serial.available()) { input[nChar++] = Serial.read();}}

    else {

      Wire.beginTransmission(1);

      //a
      Wire.write(input[0]);
      Serial.print("Drawer : ");
      Serial.println(input[0]);

      //x
      Wire.write(input[1]);
      Serial.print("Output : ");
      Serial.println(input[1]);

      //00
      Wire.write(input[2]);
      Wire.write(input[3]);
      Serial.print("Output : ");
      Serial.print(input[2]);
      Serial.println(input[3]);

      //y
      Wire.write(input[4]);
      Serial.print("Output : ");
      Serial.println(input[4]);

      //00
      Wire.write(input[5]);
      Wire.write(input[6]);
      Serial.print("Output : ");
      Serial.print(input[5]);
      Serial.println(input[6]);

      delay(15);

      while (Serial.available())
      {
        //Remove extra
        Serial.read();
      }
      Wire.endTransmission();
        nChar = 0;
        }
        }

Slave coding:

#include <Wire.h>
int ledPins[] = {7, 6, 5, 4, 3, 2,};
int ledPins2[] = {7, 6, 5, 4, 3, 2};
byte count;
byte nChar;
char c;
char input[8];
char data[50] = "";
int n;
#define nBits sizeof(ledPins)/sizeof(ledPins[0])
#define nBits sizeof(ledPins2)/sizeof(ledPins[0])



void setup()
{
  Wire.begin(1);
  Wire.onReceive(receiveEvent);
  Serial.begin(9600);
  for (byte i = 0; i < nBits; i++) {
    pinMode(ledPins[i], OUTPUT);
  }
for (byte i = 0; i < nBits; i++) {
    pinMode(ledPins2[i], OUTPUT);
    }
  Serial.begin(9600);
}

void loop()
{
  if (nChar < 8) {                    //accumulate three characters
    if (Serial.available()) {
      c = Serial.read();
      input[nChar++] = c;
    }
  }
  else {
    input[8] = 0;                   //atoi() expects string terminator
    n = atoi(input);                //convert the input characters to integer
    dispBinary(n);
    delay(100);                     //wait for any additional characters
    while (Serial.available()) {    //ignore them
      c = Serial.read();
    }
    nChar = 0;
  }
}



void receiveEvent(int howMany)
{
  while (1 < Wire.available()) {
    char c = Wire.read();
    Serial.print(c);
  }

}
void dispBinary(int n) //Vertical
{
  if (n >= 0 && n <= 6) {
    for (byte i = 0; i < nBits; i++) {
      digitalWrite (ledPins[i], n & 1);
      n /= 2;
    }
  }
}

void dispBinary2(int n) //Horizontal
{
  if (n >= 0 && n <= 6) {
    for (byte i = 0; i < nBits; i++) {
      digitalWrite (ledPins2[i], n & 1);
      n /= 2;
    }
  }

}

void b()
{
  if (data[0] != 'a')
  {
    dispBinary(atoi("00"));
    delay(100);
    dispBinary2(atoi("00"));
    delay(100);
    goto fin;
  }
  if (data[1] = 'x')
  {
    char xdata[2] = {data[2], data[3]};//(data[2], data[3]);
    dispBinary2(atoi(xdata));
    delay(100);
  }
  if (data[4] = 'y')
  {
    char ydata[2] = {data[5], data[6]};//(data[5], data[6]);
    dispBinary(atoi(ydata));
    delay(100);
  }
fin:;
}

You declare input[8] but then set input[8]=0 .
The variables in the array are numbered 0...7

Rather than doing any processing I would start by getting the master to send a single message and get the slave to print every character it input both as a printing character and in hex.

That would tell me exactly what was being sent and received.

P.S. I would get rid of the goto before somebody sees it :slight_smile:

Too late.

How are you using the same pins for Horizontal and Vertical outputs?