I need help with a little school project. I made the code, it worked, I tried to make it shorter but then it stopped reacting. What I expected to happen is by pressing the letter, related to the sequence in the Serial Monitor, it would start flickering the lights in a pattern. The problem I have now, is when I type a letter in the serial monitor console it doesn't light any LEDs nor does it give me any printlns (like "invalid input" . Here is my code:
PS: I have tried using replace all twice, but i think i fixed that. I just can't see what the problem is at the moment.
const int DELAYTIME = 100;
const int NUMBEROFPINS = 8;
const int NUMBEROFSEQUENCES= 15;
const int NUMBEROFpatternS = 8;
const int pinArray[NUMBEROFPINS] = {13, 12, 11, 10, 9, 8, 7, 6};
const int LEDsequence [NUMBEROFpatternS][NUMBEROFSEQUENCES][NUMBEROFPINS] = {
{ //pattern 0
{1,0,0,0,0,0,0,0},
{0,1,0,0,0,0,0,0},
{0,0,1,0,0,0,0,0},
{0,0,0,1,0,0,0,0},
{0,0,0,0,1,0,0,0},
{0,0,0,0,0,1,0,0},
{0,0,0,0,0,0,1,0},
{0,0,0,0,0,0,0,1}
},
{ //pattern 1
{1,0,0,0,0,0,0,1},
{0,1,0,0,0,0,1,0},
{0,0,1,0,0,1,0,0},
{0,0,0,1,1,0,0,0},
{0,0,0,1,1,0,0,0},
{0,0,1,0,0,1,0,0},
{0,1,0,0,0,0,1,0},
{1,0,0,0,0,0,0,1}
},
{ //pattern 2
{0,1,1,1,1,1,1,1},
{1,0,1,1,1,1,1,1},
{1,1,0,1,1,1,1,1},
{1,1,1,0,1,1,1,1},
{1,1,1,1,0,1,1,1},
{1,1,1,1,1,0,1,1},
{1,1,1,1,1,1,0,1},
{1,1,1,1,1,1,1,0},
{1,1,1,1,1,1,0,1},
{1,1,1,1,1,0,1,1},
{1,1,1,1,0,1,1,1},
{1,1,1,0,1,1,1,1},
{1,1,0,1,1,1,1,1},
{1,0,1,1,1,1,1,1},
{0,1,1,1,1,1,1,1},
},
{ //pattern 3
{1,0,0,0,0,0,0,1},
{1,1,0,0,0,0,1,1},
{1,1,1,0,0,1,1,1},
{1,1,1,1,1,1,1,1}
},
{ //pattern 4
{1,0,0,0,0,0,0,0},
{1,1,0,0,0,0,0,0},
{1,1,1,0,0,0,0,0},
{1,1,1,1,0,0,0,0},
{1,1,1,1,1,0,0,0},
{1,1,1,1,1,1,0,0},
{1,1,1,1,1,1,1,0},
{1,1,1,1,1,1,1,1}
},
{ //pattern 5
{0,0,0,0,0,0,0,1},
{0,0,0,0,0,0,1,1},
{0,0,0,0,0,1,1,1},
{0,0,0,0,1,1,1,1},
{0,0,0,1,1,1,1,1},
{0,0,1,1,1,1,1,1},
{0,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1}
},
{ //pattern 6
{0,0,0,0,0,0,0,0}
},
{ //pattern 7
{0,1,1,1,1,1,1,1},
{1,0,1,1,1,1,1,1},
{1,1,0,1,1,1,1,1},
{1,1,1,0,1,1,1,1},
{1,1,1,1,0,1,1,1},
{1,1,1,1,1,0,1,1},
{1,1,1,1,1,1,0,1},
{1,1,1,1,1,1,1,0},
{1,1,1,1,1,1,0,1},
{1,1,1,1,1,0,1,1},
{1,1,1,1,0,1,1,1},
{1,1,1,0,1,1,1,1},
{1,1,0,1,1,1,1,1},
{1,0,1,1,1,1,1,1},
{0,1,1,1,1,1,1,1},
}
};
int pattern = 6;
void setup(){
Serial.begin(9600);
for (int pin=0;pin<NUMBEROFPINS;pin++) {
pinMode(pinArray[pin], OUTPUT); // we make all the declarations at once
};
}
void loop() {
char incomingByte;
for (int sequence=0;sequence<NUMBEROFSEQUENCES;sequence++) {
for (int pin=0;pin<NUMBEROFPINS;pin++) {
digitalWrite(pinArray[pin], LEDsequence[pattern][sequence][pin]);
}
delay(DELAYTIME);
if (Serial.available() > 0){
incomingByte = Serial.read();
switch (incomingByte){
case 72: pattern = 7; // is een 'H'
break;
case 104: pattern = 2; // is een 'h'
break;
case 83: pattern = 1; // is een 'S'
break;
case 115: pattern = 3; // is een 's'
break;
case 82: pattern = 4; // is een 'R'
break;
case 76: pattern = 5; // is een 'L'
break;
case 69: pattern = 6; // is een 'E'
break;
case 65: pattern = 0; // is een 'A'
break;
default:
pattern = 6;
Serial.println("Invalid input");
break;
}
}
}
}