I am working on a simple project on talking to the serial monitor, and my only global variable ("int" type, named "incomingByte") is consuming a lot of memory. There is no problem on running the scketch, but I am not satisfied to have it that way.
When I load it, I receive: "Global variables use 390 bytes (19%) of dinamic memory...". Why is it happening, and how could I fix this?
int incomingByte = 0; //for the incoming serial data
void setup() {
// put your setup code here, to run once:
randomSeed(analogRead(0)); //starts the pseudo-random sequence in a random point
Serial.begin(9600);
//waits for serial initialization to send the messages:
//(Serial) returns false for serial off, and true for serial on. This is inverted with !.
while(!Serial){
;
}
//sending instructions:
Serial.println("Initializing...");
Serial.println(" ");
delay(2000);
Serial.println("Please select an option:");
Serial.println("1 - greetings");
Serial.println("2 - random number");
Serial.println("3 - calculator");
Serial.println(" ");
}
void loop() {
// put your main code here, to run repeatedly:
if(Serial.available() > 0){
incomingByte = Serial.read(); // Serial.read() returns the first byte of incoming data
//recognizing the command received:
if (incomingByte == '1'){
numberOne();
delay(1500);
Serial.println("Waiting; choose another option");
Serial.println(" ");
}
if (incomingByte == '2'){
numberTwo();
delay(1500);
Serial.println("Waiting; choose another option");
Serial.println(" ");
}
if (incomingByte == '3'){
numberThree();
delay(1500);
Serial.println("Waiting; choose another option");
Serial.println(" ");
}
}
}
void numberOne() {
Serial.println("Hello, Vitor! Good to see you!");
}
void numberTwo() {
//sets the random number to be picked between [0, 101[
long randomNum = random(0, 101);
Serial.print("Your random number is: ");
Serial.println(randomNum, DEC);
}
void numberThree(){
Serial.println("Tool not available yet");
}
Serial
) also use some of the RAM