I'm trying to get my program to call a subroutine when the letter "i" is sent from the serial monitor. Here's the relevant code. I know the value of key is "i" because it prints it to the serial monitor the line before, but it still does not seem to trigger the if condition.
void setup() {
pinMode(10,OUTPUT); // Main Menu LED
pinMode(11, OUTPUT); // Initiative LED
delay(2000);
FastLED.addLeds<WS2812, DATA_PIN, GRB>(leds, NUM_LEDS);
Serial.begin(9600);
}
void loop() {
char key="X";
digitalWrite(10, HIGH);
if (Serial.available()){
key=Serial.read();
Serial.println(key);
if(key=="i"){
Initiative();
}
}
}
void Initiative() {
digitalWrite(10, LOW);
digitalWrite(11, HIGH);
delay(5000);
char key="X";
int order = 0;
int battle[15]; //Initalize for 15 possible turns in a round of combat
//Set Initiative Order ending when the key "0" is pressed
I separately sent each of the following values through the serial monitor, but even when I got to "i" it didn't send it to the subroutine.
5
5
6
4
1
i
I'm quite content to have it be some dumb thing like missing a ; somewhere, but what wouldn't even compile.
(The long end goal is to highlight players turns in initiative with an addressable LED strip when we play d&d)