I am currently working on a project to control a portable heat pump with a phone app via blue tooth.
I am currently working on a method to switch from heating to cooling mode by sending a c or h to the serial port, reading it and then adjust the integer value of (mode) based on whether a c or h is received over the serial bus.
I can't seem to get mode to change its value. it always returns a value of 0 to the serial bus.
Any help would be greatly appreciated!
Code below.
int mode;
char (m);
void setup() {
Serial.begin(9600);
}
void loop() {
//Check for incoming serial commands from bluetooth, a value of h for heating and c for cooling.
// If h, set mode equal to 1.
// If c, set mode equal to -1
if (Serial.available() > 0) //If something is on the serial line...read it.
{
char (m) = Serial.read(); //Assign the character m to the value on the incoming serial line.
Serial.println (m); //Print the the value (m).
if (char (m)="h") //If the the incoming serial value is "h".
{
int (mode) = 1; //Set the value of (mode) eqaul to 1.
}
else //Otherwise
int (mode) = -1; //Set the value of (mode) equal to -1.
}
Serial.println (mode); //Print the value of (mode)
delay (1000);
}