LED doesn't want to light up

Hello!
I want to build Arduino Piano, that on the same time teaches you how to play on it.
It has got LEDs, that should light up when I use a learn mode. Each LED is for each button. When it lights up, that should mean, that we have to press that button.
No LEDs light up.
This is my code:

#include <Tone.h>

// Kuža pazi - notes converted
// Copyright
int notes_kuzapazi[] = {NOTE_C4, NOTE_C4, NOTE_C4, NOTE_C4, NOTE_D4, NOTE_D4, NOTE_D4, NOTE_D4, NOTE_E4, NOTE_E4, NOTE_D4, NOTE_D4, NOTE_C4, NOTE_C4, NOTE_C4, NOTE_C4};

// Here are defined some important variables
int note = 0;
char text;
boolean songlearn = false;

// Here are defined LEDs for learning
const int led_c1 = 11;
const int led_d1 = 12;
const int led_e1 = A0;
const int led_f1 = A1;
const int led_g1 = A2;
const int led_a1 = A3;
const int led_h1 = A4;               // USA uses B instead H
const int led_c2 = A5;

// Here are defined all the buttons for playing
const int c1 = 2;
const int d1 = 3;
const int e1 = 4;
const int f1 = 5;
const int g1 = 6;
const int a1 = 7;
const int h1 = 8;                    // USA uses B instead H
const int c2 = 9;
const int speaker = 10;

Tone tone1;   // Here are tones defined

// Function to turn all leds off
void turnoffall(){
  digitalWrite(led_c1, LOW);
  digitalWrite(led_d1, LOW);
  digitalWrite(led_e1, LOW);
  digitalWrite(led_f1, LOW);
  digitalWrite(led_g1, LOW);
  digitalWrite(led_a1, LOW);
  digitalWrite(led_h1, LOW);
  digitalWrite(led_c2, LOW);
}

void kuzapazi_refren(){
  for (note = 0; 15 > note; note++){
    tone1.play(notes_kuzapazi[note]);
    delay(250);
    tone1.stop();
    delay(100);
  }
}

void kuzapazi_learn(){
  for (note = 0; 15 > note; note++){
    songlearn = true;
    text = notes_kuzapazi[note];
    Serial.println(note);
    while (songlearn==true){
      if (text=="NOTE_C4"){
        Serial.println(text);
        digitalWrite(led_c1, HIGH);
        if (digitalRead(c1)==HIGH){
          turnoffall();
          songlearn=false;
        }
      }
      else if (text=="NOTE_D4"){
        Serial.println("d1");
        digitalWrite(led_d1, HIGH);
        if (digitalRead(d1)==HIGH){
          turnoffall();
          songlearn=false;
        }
      }
      else if (text==NOTE_E4){
        Serial.println("e1");
        digitalWrite(led_e1, HIGH);
        if (digitalRead(e1)==HIGH){
          turnoffall();
          songlearn=false;
        }
      }
    }
  }
}

void setup() {
  // Define speaker
  pinMode(speaker, OUTPUT);
  tone1.begin(speaker);

  // Serial begin
  Serial.begin(9600);

  // Define Buttons
  pinMode(c1, INPUT);
  pinMode(d1, INPUT);
  pinMode(e1, INPUT);
  pinMode(f1, INPUT);
  pinMode(g1, INPUT);
  pinMode(a1, INPUT);
  pinMode(h1, INPUT);
  pinMode(c2, INPUT);

  // Define LEDs
  pinMode(led_c1, OUTPUT);
  pinMode(led_d1, OUTPUT);
  pinMode(led_e1, OUTPUT);
  pinMode(led_f1, OUTPUT);
  pinMode(led_g1, OUTPUT);
  pinMode(led_a1, OUTPUT);
  pinMode(led_h1, OUTPUT);
  pinMode(led_c2, OUTPUT);
  
  turnoffall();
  kuzapazi_learn();
}

void loop() {
  if (digitalRead(c1)==HIGH){
    tone1.play(NOTE_C4);
    Serial.println("c1");
    delay(30);
    tone1.stop();
  }
  else if (digitalRead(d1)==HIGH){
    tone1.play(NOTE_D4);
    Serial.println("d1");
    delay(30);
    tone1.stop();
  }
  else if (digitalRead(e1)==HIGH){
    Serial.println("e1");
    tone1.play(NOTE_E4);
    delay(30);
    tone1.stop();
  }
  else if (digitalRead(f1)==HIGH){
    Serial.println("f1");
    tone1.play(NOTE_F4);
    delay(30);
    tone1.stop();
  }
  else if (digitalRead(g1)==HIGH){
    Serial.println("g1");
    tone1.play(NOTE_G4);
    delay(30);
    tone1.stop();
  }
  else if (digitalRead(a1)==HIGH){
    Serial.println("a1");
    tone1.play(NOTE_A4);
    delay(30);
    tone1.stop();
  }
  else if (digitalRead(h1)==HIGH){
    Serial.println("h1");
    tone1.play(NOTE_B4);
    delay(30);
    tone1.stop();
  }
  else if (digitalRead(c2)==HIGH){
    Serial.println("c2");
    tone1.play(NOTE_C5);
    delay(30);
    tone1.stop();
  }
}

I'm using a Tone library.
Does anybody know what is wrong?
Thank you so much
Mitjas

notes_kuzapazi is an int array. It contains numbers not text.

The variable text is a single char. It can never be equal to a String like "NOTE_C4".

Steve

Hello and thank you so much :wink: !
I fixed that and works like a charm. :slight_smile:
Thank you
-mitjas


Github: mytja (Mitja) · GitHub