Guys wait here that was solution 1 though the second error is my while loop doesn't let the Serial to print a thing.
Code:
int switchPin3 = 18;
int switchVal3 = 1;
String msg("Please input your number");
int answer;
void setup() {
// put your setup code here, to run once:
pinMode(switchPin3, INPUT);
Serial.begin(115200);
}
void loop() {
// put your main code here, to run repeatedly:
switchVal3 = digitalRead(switchPin3);
Serial.println(switchVal3);
Serial.println(msg);
while (Serial.available() == 0) {}
}
int switchPin3=18;
int switchVal3=1;
String msg ("Please input your number");
int answer;
void setup() {
// put your setup code here, to run once:
pinMode(switchPin3,INPUT);
Serial.begin(115200);
}
void loop() {
// put your main code here, to run repeatedly:
switchVal3=digitalRead(switchPin3);
Serial.println(switchVal3);
Serial.println(msg);
while(Serial.read()==0){}
}
I will offer you some advice, but I will not correct your coding issues. The reason for that is because you don't understand the hardware and software architecture.
Spend an hour or two reading up on how microcontrollers work, it's architecture. Then read up on libraries, both device (aka. driver) libraries and helper libraries. When you understand those, you will come to realise that you can use Google to search for Arduino Serial Library.
When you search that, you will have access to all the functions (and their arguments) in the Serial library. As an added bonus, you will also have access to how to use the Serial library in your code.
Forums aren't there to spoon-feed or do your homework for you. I have given you enough information to get you started on the right path, but you will have to do the walking.
EDIT:
Also make sure you understand why the setup() and loop() functions are mandatory within your sketch and what each of these functions do, especially the loop() function.
Alrighty then, if you are willing to work, I will help you. However, I am not going to do your homework for you. And remember, on the forums, nothing is urgent.
There are two areas in the code you are struggling with:
How to use Serial,
You don't understand the While loop (conditional statement)
Both are easy to solve. You managed to find the forum, for that I am sure you will be able to locate all the information about Serial if you do a search for it, using your favourite browser. Example, if you search for "Arduino Serial", you will find all the information you need about the Serial library, including examples of how to use it.
FYI: Because Serial is an internal library that comes with the Arduino IDE, you are not required to define it at the top of your sketch, like you need to do with other libraries - it is already included (default) in your Arduino IDE.