Im coding a parachute to deploy at a certain altitude using a pressure sensor, the code for that has all been figured out, however i want a message to be displayed after the parachute has deployed however with the code
if (temperature >= 28 ){servo.write(90);
Serial.print ("Prachute Deployed");
}
it will constantly show the "Parachute deployed" message at a rate of twice per second, and i was wondering if there was a way to prevent this and for it to only show once
(the temperature command is only for testing the final product will use temperature)
printFlag = true;
. . .
if (temperature >= 28 )
{
servo.write(90);
if (printFlag == true)
{
Serial.print ("Prachute Deployed");
printFlag = false;
}
}
Quick and dirty:
if (temperature >= 28 && servo.read() != 90)
{
servo.write(90);
Serial.print ("Prachute Deployed");
}
Note: servoRead() just returns the last position you set the servo to. It does not return the actual position of the servo.
Where does the first line "printFlag = true;" go in the code?
Make it global i.e. place it before setup()
i get this error message
Arduino: 1.8.12 (Windows 10), Board: "Arduino Uno"
Temperature_and_pressure:19:1: error: 'printFlag' does not name a type; did you mean 'printf_P'?
printFlag = true;
^~~~~~~~~
printf_P
C:\Users\Morgan\Documents\Arduino\Temperature_and_pressure\Temperature_and_pressure.ino: In function 'void loop()':
Temperature_and_pressure:49:1: error: 'printFlag' was not declared in this scope
printFlag = true;
^~~~~~~~~
C:\Users\Morgan\Documents\Arduino\Temperature_and_pressure\Temperature_and_pressure.ino:49:1: note: suggested alternative: 'printf_P'
printFlag = true;
^~~~~~~~~
printf_P
Temperature_and_pressure:58:1: error: expected '}' at end of input
}
^
exit status 1
'printFlag' does not name a type; did you mean 'printf_P'?
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Try:
bool printFlag = true;
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.