Piezo KnockSensor can't read input and do sounds separately?

Hey! I’ve made this project. The idea is, when the temperature reader reaches +24 degrees, it will play a sound from a piezo knock sensor, and do a flashing light with the yellow bulb.
At the same time, the knock sensor will take inputs as i tap on it. If it reaches above the set threshold, it will change the red LED to the green LED.

It works separately, but not together.

Any tips?

//variabler til lås
const int redPin = 13;
const int greenPin = 12;
const int knockSensor = A1;
const int threshold = 100;
int sensorReading = 0;
int lockLedState = HIGH;

//variabler til temperatur
const int temperaturePin = A4;
const int yellowPin =  11;
int temperaturLedState = HIGH;
unsigned long previousMillis = 0;
int tempRead = 0;

//variabler til lyd
int soundLedState = LOW;
//knockSensor A1, noteA, noteB;

char ON_OFF;

void setup() {
  Serial.begin(9600);
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(yellowPin, OUTPUT);
}

void loop() {
  sensorReading = analogRead(knockSensor);
  lockSensor();
  getTemperature(temperaturePin);
  delay(500);
}

float getTemperature(int temperaturePin) {
  float voltRead = analogRead(temperaturePin);
  float volt = voltRead * (5.0 / 1023);
  float voltInCelc = (volt - 0.5) * 100;
//  Serial.println(voltInCelc);

  if (voltInCelc >= 25 || voltInCelc <= 1) { //Til tests er det 24 - normalt køleskab er måske maks 7 *c.
    ON_OFF = 'A';
    temperaturAlarm(50);
    piezoSound();
  } else {
    ON_OFF = 'B';
    getTemperature(temperaturePin);
    Serial.print("Reset");
  }
  return voltInCelc;
}

void temperaturAlarm(int interval) {
  unsigned long currentMillis = millis();
  if (ON_OFF == 'A') {
    if (currentMillis - previousMillis >= interval) {
      previousMillis = currentMillis;

      if (temperaturLedState == LOW) {
        temperaturLedState = HIGH;
        soundLedState = HIGH;
      } else {
        temperaturLedState = LOW;
        soundLedState = LOW;
      }
      digitalWrite(yellowPin, temperaturLedState);
    }
  }
}

void piezoSound() {
  if (ON_OFF == 'A') {
    const int noteA = 440;
    const int noteB = 750;
    if (soundLedState == LOW) {
      tone(knockSensor, noteA);
    } else if (soundLedState == HIGH) {
      tone(knockSensor, noteB);
    }
  }
}

void lockSensor() {
  Serial.print(sensorReading);

  if (ON_OFF == 'B') {
    if (sensorReading >= threshold) {
      lockLedState = !lockLedState;
      digitalWrite(greenPin, lockLedState);
    } else {
      digitalWrite(redPin, !lockLedState);
      delay(200);
    }
  }
}



//LAV EN LAMPE DER KAN JUSTERE LYSSTYRKE FRA DREJEKNAP
//ENTEN BOOLEAN ELLER SEND TIL PROCESSING ELLER GOTO
//FRITZING

//MANGLER: LockSensor virker ikke ordenligt.

Thanks!
Regards, Simon.

if (ON_OFF = 'A')Oops!

jremington:
if (ON_OFF = 'A')Oops!

Haha what :)?
I know about booleans, but my university requires to use the “old fashioned” C language - and bools didn’t exist in the 80’s - you either used ints or chars, and changed their value. So basically the same.

ON = A
OFF = B.

EDIT: Ah f*ck i now noticed my mistake. Will fix it, and see if it works :-)!
Too tired yesterday i guess.

EDIT2: Still doesn’t work. I’ve updated the code with correct ==.
Any ideas @jremington?
I believe its in the " getTemperature(temperaturePin);" method, because if i comment it out, the knock sensor works perfectly.

EDIT3: So apparently everything works now. The mysteries lied within the fusing i think. Not sure.

Another issue:

Since arduino code runs forever - i have a slight challenge of having the sound stopped, when the temperature reaches below 24 degrees.

Any advice here? The char-boolean doesn't cut it :confused:

Simon