I have been working on a terminal program that gets input from a user and runs the code under an if statement based off the input however, when I compile it I get a invaild conversion from const char to int error and when the program run's every bit of code runs at once. Any info will help .
#include <MemoryUsage.h>
int optionSelection;
String onResponse = "Testing";
void setup() {
// put your setup code here, to run once:
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(9600);
delay(500);
Serial.print("OS Version 0.5");
Serial.print(" ");
FREERAM_PRINT;
Serial.print(" ");
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println("What do you want to do?");
optionSelection = Serial.parseInt();
if (optionSelection = "1") {
Serial.print("Option 1");
}
else if (optionSelection = "2"); {
Serial.print("Option 2");
}
}
Welcome to the forum. Thanks for using code tags in your first post. Many don't
I removed the library from the code and whatever FREERAM_PRINT; is supposed to do and it compiles
Please post the full error that you get by using the "Copy error message" button in the IDE and post it here in code tags
Although I can compile your code it will not do what you think. In it you have
optionSelection = Serial.parseInt();
if (optionSelection = "1")
optionSelection is an int, So far, so good, but you are trying to compare it to a String instead of an int. In addition to that you have the syntax if the if wrong. use = for assignment and == for comparison
C:\Users\************\Desktop\OS\OS.ino: In function 'void loop()':
C:\Users\************\Desktop\OS\OS.ino:21:23: warning: invalid conversion from 'const char*' to 'int' [-fpermissive]
if (optionSelection = "1") {
^
C:\Users\************\Desktop\OS\OS.ino:24:28: warning: invalid conversion from 'const char*' to 'int' [-fpermissive]
else if (optionSelection = "2"); {
^
A issue has arisen after fixing some of the issues. When I enter a command, no matter which one I get the same response where the program prints both options at once. Here is what it looks like:
Option 1Option 2What do you want to do?
Option 1Option 2What do you want to do?