Switch only executes first case

Im trying to send data from Processing to arduino and then draw a letter on an 8*8 matrix.
Only the first letter works

#include "LedControl.h"

int val = 0;

LedControl lc = LedControl(7, 5, 6, 1);

void setup() {
  lc.shutdown(0, false);
  lc.setIntensity(0, 8);
  lc.clearDisplay(0);
  Serial.begin(9600);
}

void loop() {
}


void setChar(int c) {
  lc.clearDisplay(0);


  switch (c) {
    case 0:
      int pixels1_a[] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 7, 7};
      int pixels2_a[] = {3, 4, 2, 5, 2, 5, 1, 6, 1, 6, 1, 2, 3, 4, 5, 6, 1, 6, 1, 6};
      setPixlsAt(pixels1_a, pixels2_a, 20);
      break;
    case 1:
      int pixels1_b[] = {0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 7, 7};
      int pixels2_b[] = {1, 2, 3, 4, 1, 5, 1, 4, 1, 2, 3, 1, 4, 1, 5, 1, 5, 1, 2, 3, 4};
      setPixlsAt(pixels1_b, pixels2_b, 21);
      break;
    case 2:
      int pixels1_c[] = {0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 7, 7};
      int pixels2_c[] = {3, 4, 5, 2, 1, 1, 1, 1, 2, 3, 4, 5};
      setPixlsAt(pixels1_c, pixels2_c, 12);
      break;
    case 3:
      int pixels1_d[] = {0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 7, 7};
      int pixels2_d[] = {1, 2, 3, 4, 1, 5, 1, 6, 1, 6, 1, 6, 1, 6, 1, 5, 1, 2, 3, 4};
      setPixlsAt(pixels1_d, pixels2_d, 20);
      break;
    case 4:
      int pixels1_e[] = {0, 0, 0, 0, 0, 0, 1, 2, 3, 3, 3, 3, 3, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7};
      int pixels2_e[] = {1, 2, 3, 4, 5, 6, 1, 1, 1, 2, 3, 4, 5, 6, 1, 1, 1, 1, 2, 3, 4, 5, 6};
      setPixlsAt(pixels1_e, pixels2_e, 23);
      break;
    case 5:
      int pixels1_f[] = {0, 0, 0, 0, 0, 0, 1, 2, 3, 3, 3, 3, 3, 3, 4, 5, 6, 7};
      int pixels2_f[] = {1, 2, 3, 4, 5, 6, 1, 1, 1, 2, 3, 4, 5, 6, 1, 1, 1, 1};
      setPixlsAt(pixels1_f, pixels2_f, 18);
      break;
    case 6:
      int pixels1_g[] = {0, 0, 0, 0, 1, 1, 2, 3, 4, 4, 4, 4, 5, 5, 6, 6, 7, 7, 7, 7};
      int pixels2_g[] = {2, 3, 4, 5, 1, 6, 1, 1, 1, 4, 5, 6, 1, 6, 1, 6, 2, 3, 4, 5};
      setPixlsAt(pixels1_g, pixels2_g, 20);
      break;
    case 7:
      int pixels1_h[] = {0, 0, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7};
      int pixels2_h[] = {1, 6, 1, 6, 1, 6, 1, 2, 3, 4, 5, 6, 1, 6, 1, 6, 1, 6, 1, 6};
      setPixlsAt(pixels1_h, pixels2_h, 20);
      break;
    case 8:
      int pixels1_i[] = {1, 2, 3, 4, 5, 6, 7};
      int pixels2_i[] = {4, 4, 4, 4, 4, 4, 4};
      setPixlsAt(pixels1_i, pixels2_i, 7);
      break;
    case 9:
      int pixels1_j[] = {0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 7, 7, 7};
      int pixels2_j[] = {1, 2, 3, 4, 4, 4, 4, 4, 4, 1, 2, 3, 4};
      setPixlsAt(pixels1_j, pixels2_j, 13);
      break;
    case 10:
      int pixels1_k[] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7};
      int pixels2_k[] = {1, 5, 1, 4, 1, 3, 1, 2, 1, 3, 1, 3, 1, 4, 1, 5};
      setPixlsAt(pixels1_k, pixels2_k, 16);
      break;
    case 11:
      int pixels1_l[] = {0, 1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7};
      int pixels2_l[] = {1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 5};
      setPixlsAt(pixels1_l, pixels2_l, 12);
      break;
    case 12:
      int pixels1_m[] = {0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7};
      int pixels2_m[] = {0, 7, 0, 1, 6, 7, 0, 1, 6, 7, 0, 2, 5, 7, 0, 2, 5, 7, 0, 3, 4, 7, 0, 3, 4, 7, 0, 3, 4, 7};
      setPixlsAt(pixels1_m, pixels2_m, 30);
      break;
    case 13:
      int pixels1_n[] = {0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7};
      int pixels2_n[] = {1, 2, 6, 1, 2, 6, 1, 3, 6, 1, 3, 6, 1, 4, 6, 1, 4, 6, 1, 5, 6, 1, 5, 6};
      setPixlsAt(pixels1_n, pixels2_n, 24);
      break;
    case 14:
      int pixels1_o[] = {0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 7, 7};
      int pixels2_o[] = {2, 3, 4, 5, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 2, 3, 4, 5};
      setPixlsAt(pixels1_o, pixels2_o, 20);
      break;
    case 15:
      int pixels1_p[] = {0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 5, 6, 7};
      int pixels2_p[] = {1, 2, 3, 4, 1, 5, 1, 5, 1, 5, 1, 2, 3, 4, 1, 1, 1};
      setPixlsAt(pixels1_p, pixels2_p, 17);
      break;
    case 16:
      int pixels1_q[] = {0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7};
      int pixels2_q[] = {2, 3, 4, 5, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 2, 3, 4, 5, 6};
      setPixlsAt(pixels1_q, pixels2_q, 19);
      break;
    case 17:
      int pixels1_r[] = {0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5, 6, 6, 7, 7};
      int pixels2_r[] = {1, 2, 3, 4, 1, 5, 1, 5, 1, 5, 1, 2, 3, 4, 1, 5, 1, 5, 1, 6};
      setPixlsAt(pixels1_r, pixels2_r, 20);
      break;
    case 18:
      int pixels1_s[] = {0, 0, 0, 0, 1, 2, 3, 3, 4, 4, 5, 6, 7, 7, 7, 7};
      int pixels2_s[] = {2, 3, 4, 5, 1, 1, 2, 3, 4, 5, 6, 6, 2, 3, 4, 5};
      setPixlsAt(pixels1_s, pixels2_s, 16);
      break;
    case 19:
      int pixels1_t[] = {1, 1, 1, 1, 1, 2, 3, 4, 5, 6, 7};
      int pixels2_t[] = {2, 3, 4, 5, 6, 4, 4, 4, 4, 4, 4};
      setPixlsAt(pixels1_t, pixels2_t, 11);
      break;
    case 20:
      int pixels1_u[] = {1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 7, 7};
      int pixels2_u[] = {1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 2, 3, 4, 5};
      setPixlsAt(pixels1_u, pixels2_u, 16);
      break;
    case 21:
      int pixels1_v[] = {1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7};
      int pixels2_v[] = {1, 6, 1, 6, 1, 6, 1, 5, 2, 5, 2, 5, 3, 4};
      setPixlsAt(pixels1_v, pixels2_v, 14);
      break;
    case 22:
      int pixels1_w[] = {1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7};
      int pixels2_w[] = {0, 7, 0, 7, 0, 3, 4, 7, 0, 3, 4, 7, 1, 3, 4, 6, 1, 3, 4, 6, 2, 5};
      setPixlsAt(pixels1_w, pixels2_w, 22);
      break;
    case 23:
      int pixels1_x[] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7};
      int pixels2_x[] = {1, 6, 2, 5, 2, 5, 3, 4, 3, 4, 2, 5, 2, 5, 1, 6};
      setPixlsAt(pixels1_x, pixels2_x, 16);
      break;
    case 24:
      int pixels1_y[] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7};
      int pixels2_y[] = {1, 6, 1, 6, 1, 6, 2, 5, 2, 5, 3, 4, 3, 4, 3, 4};
      setPixlsAt(pixels1_y, pixels2_y, 16);
      break;
    case 25:
      int pixels1_z[] = {0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7};
      int pixels2_z[] = {1, 2, 3, 4, 5, 6, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6};
      setPixlsAt(pixels1_z, pixels2_z, 18);
      break;
    default:
      break;
  }
}

void setPixlsAt(int r[], int c[], int s) {
  for (int i = 0; i < s; i++) {
    lc.setLed(0, r[i], c[i], true);
  }

}

void serialEvent() {
  val = Serial.read();
  setChar(val);
}

Im using a library to control the led matrix, but it doesnt change anything

void serialEvent() {
  val = Serial.read();
  setChar(val);
}

Where, exactly, are the characters coming from, and what is being sent? If from the serial monitor, “val” will be the numeric value of the ASCII character sent.

Perhaps you meant to write:

  switch (c) {
    case '0':
      ......
    case '1':
      .......

MarkT:
Perhaps you meant to write:

  switch (c) {

case '0':
      ......
    case '1':
      .......

I'll try that but i think it will execute every case then

What do your debug prints tell you?

What is being sent to your sketch?

Why are you wasting so much RAM?

I'll try that but i think it will execute every case then

Very silly way to proceed.

If you KNOW what is being sent, you can write code that will execute correctly. Please answer the questions you were asked.

jremington:

void serialEvent() {

val = Serial.read();
  setChar(val);
}




Where, exactly, are the characters coming from, and **what** is being sent? If from the serial monitor, "val" will be the numeric value of the ASCII character sent.

Im Using Processing to send the characters. a = 0, b = 1...

Are you sending 0, or ‘0’?

Processing Sketch:

import processing.serial.*;

Serial port;

int val;

void setup() {
size(800, 800);
port = new Serial(this, Serial.list()[0], 9600);
}

void draw() {
background(0);
}

void keyPressed() {
switch(key) {
case 'a':
val = 0;
break;
case 'b':
val = 1;
break;
case 'c':
val = 2;
break;
case 'd':
val = 3;
break;
case 'e':
val = 4;
break;
case 'f':
val = 5;
break;
case 'g':
val = 6;
break;
case 'h':
val = 7;
break;
case 'i':
val = 8;
break;
case 'j':
val = 9;
break;
case 'k':
val = 10;
break;
case 'l':
val = 11;
break;
case 'm':
val = 12;
break;
case 'n':
val = 13;
break;
case 'o':
val = 14;
break;
case 'p':
val = 15;
break;
case 'q':
val = 16;
break;
case 'r':
val = 17;
break;
case 's':
val = 18;
break;
case 't':
val = 19;
break;
case 'u':
val = 20;
break;
case 'v':
val = 21;
break;
case 'w':
val = 22;
break;
case 'x':
val = 23;
break;
case 'y':
val = 24;
break;
case 'z':
val = 25;
break;
}
port.write(val);
println(val);
}

TheMemberFormerlyKnownAsAWOL:
Are you sending 0, or '0'?

Im sending an integer with value 0 for 'a'

if (key >= 'a' && key <= 'z' ) {
   val = key - 'a';
}

. Much easier to read.

Please use code tags when posting code.

Also, please explain this statement: "Only the first letter works", by telling us what you entered, what you expected to happen, and what happened instead.

What does Processing do with a port.write of an int?

jremington:
Please use code tags when posting code.

Also, please explain this statement: "Only the first letter works", by telling us what you entered, what you expected to happen, and what happened instead.

I run my Processing sketch, press a key, a value from 0 to 25 is sent. If the value sent is 0 the display shows an a. Anything else will just clear the matrix. If i swap case 0: and case 1: the matrix will display a b instead

TheMemberFormerlyKnownAsAWOL:
What does Processing do with a port.write of an int?

It converts to byte and sends it to the arduino. it Serial.read() it and uses that to display a letter.

Using byte instead of int has the same result

You should write a simple program to figure out how to reliably transfer single bytes of data between Processing and the Arduino, before adding all the other stuff.

It should go without saying that there is no need to translate the character 'a' to an integer zero, send that, and convert that zero back into an 'a' on the Arduino end.

Try reducing all those tables to “byte”

TheMemberFormerlyKnownAsAWOL:
Try reducing all those tables to "byte"

didnt change anything

kport_01:
didnt change anything

It should have halved the RAM usage.
I’m surprised.

When you figure out how to successfully and reliably transfer a byte of information from Processing to Arduino, please let us know how you did it!