Did you try to do the initialization in the setup() function, "just in the case"? Something like:
void setup()
{
myServo.attach(motorSwitch); // Connect servo control to digital pin 8
myServo.write(0); // Tell servo to go to 0 degrees
position = 0; // Store initial lever position at 0 degrees
// Set up the pushbutton pins to be an input:
pinMode(setThermo, INPUT);
pinMode(resetThermo, INPUT);
pinMode(motorSwitch, OUTPUT);
Serial.begin(9600);
promptMenu = true;
}
EDIT: One more thing. Why you have this boolean var defined like:
luisilva:
Did you try to do the initialization in the setup() function, "just in the case"? Something like:
???? Luisilva... you should know that initializing a global variable should make it global!
OP... assuming your code (you put only partial, so I added a few brackets) was this:
//Servo myServo; // servo control object
int position; // Save motor position
const int setThermo = 9; // pushbutton 1 pin
const int resetThermo = 10; // pushbutton 2 pin
bool thermo_is_set = false;
const int temperaturePin = 0;
const int motorSwitch = 8; // Switch Pin
float voltage, degreesC, degreesF;
int incomingByte = 0;
boolean promptMenu = true;
void setup()
{
//myServo.attach(motorSwitch); // Connect servo control to digital pin 8
//myServo.write(0); // Tell servo to go to 0 degrees
position = 0; // Store initial lever position at 0 degrees
// Set up the pushbutton pins to be an input:
pinMode(setThermo, INPUT);
pinMode(resetThermo, INPUT);
pinMode(motorSwitch, OUTPUT);
Serial.begin(9600);
}
void loop()
{
if(promptMenu == true)
{
// Do not prompt menu until user desires
promptMenu = false;
Serial.println("Please choose an option:");
Serial.println("a: Measure ambient temperature");
Serial.println("b: Turn on A/C");
Serial.println("c: Turn on Heat");
}
}
it worked fine for me...
You are initializing promtMenue to true, and therefore you are doing this block of code:
if(promptMenu == true)
{
// Do not prompt menu until user desires
promptMenu = false;
Serial.println("Please choose an option:");
Serial.println("a: Measure ambient temperature");
Serial.println("b: Turn on A/C");
Serial.println("c: Turn on Heat");
}
which toggles promptMenu to false...
Add a serial print here:
void loop()
{
Serial.print("promptMenue = ");
Serial.println(promptMenu);
if(promptMenu == true)
{
// Do not prompt menu until user desires
promptMenu = false;
I had put some print statements before my initial if statement in my loop() function and it was indeed printing "0" to my serial console. So for some reason, by the time I begin the loop() function, promptMenu has already been turned to false or from what I assumed was not initialized at all to begin with. However, since I also tried setting the variable to true inside setup() and it was STILL returning false in the loop() function, I figured something was wrong with my variable(I have no idea..).
I put print statements before and after my if() loop and it would always skip the whole loop, leading my to believe something went wrong when first initializing the variable.
I have attached my complete program for reference(sorry for the jumble)
luisilva:
Did you try to do the initialization in the setup() function, "just in the case"? Something like:
???? Luisilva... you should know that initializing a global variable should make it global!
(...)
I don't understand. What I was thinking was "and if somewhere between the initialization and the test (in the if) for some reason the variable change his value?". I don't see the relation between this and the variable being or not global. If the variable was not global he get a compiling error and not a different value in the variable, right?
Welp, I knew it was just something silly. I did not put any delay before printing my menu so by the time my serial console box opened, the menu had already been "shown" and then the variable was set to false so it would never show again. It just looked like it never showed up to begin with. After putting some delay in, I can see the menu now fine.
I agree with JimboZA. what you describe should not be a problem, because the console reset your board. Like I said, your code is fine, because I test it and it work for me.