I'm working on some code on a Teensy 2.0 to read a pressure sensor, turn that input into a text string, and output that string using the onboard hardware serial. Here's the code that I think is most directly relevant:
char outString[17];
HardwareSerial Uart = HardwareSerial();
float pressure = 0;
sprintf(outString,"OPT,%04.4,0000",pressure);
Uart.println (outString);
When I attempt to compile, it errors out with the error in the subject, and the last line (Uart.println) marked. A web search suggests that this error comes up when you forget a () following a function call, but that doesn't seem to be the case here. Any ideas what's up?
As an unrelated question, I'm not at all sure my sprintf expression makes any sense. What I'm trying to do is turn the pressure reading into a four-digit integer, padded with zeroes as appropriate. So, if pressure=85.2, the string should read OPT,0085,0000.
Complete code is below:
const int sensorInPin = A0;
const int warningInPin = A1;
const int ledOutPin = 11;
unsigned long previousMillisPoll = 0;
unsigned long previousMillisFlash = 0;
unsigned long currentMillis = 0;
long pollInterval = 250; // poll every 250 ms
long flashInterval = 125; // 4 Hz flash (8 transitions/sec)
int ledState = LOW;
boolean warningFlag = false;
boolean debug = true;
int sensorValue = 0;
int warningValue = 0;
float pressureMultiplier = 4.982; // experimentally derived - divide sensor reading by this to yield PSI
char outString[17];
HardwareSerial Uart = HardwareSerial();
float pressure = 0;
void setup() {
pinMode (ledOutPin, OUTPUT);
if (debug == true) {
Serial.begin (38400);
}
Uart.begin (9600);
warningValue = analogRead(warningInPin);
}
void loop() {
currentMillis = millis();
if (currentMillis - previousMillisPoll > pollInterval) {
previousMillisPoll = currentMillis;
sensorValue = analogRead (sensorInPin);
pressure = sensorValue / pressureMultiplier;
if ( sensorValue < warningValue) {
warningFlag = true;
}
else {
warningFlag = false;
}
sprintf(outString,"OPT,%04.4,0000",pressure);
Uart.println (outString);
if (debug == true) {
Serial.print ("Warning Value: ");
Serial.println (warningValue);
Serial.print ("Sensor Value: ");
Serial.println (sensorValue);
Serial.print ("Calculated Pressure: ");
Serial.println (pressure);
Serial.println (outString);
Serial.println ;
}
}
if (warningFlag == true && currentMillis - previousMillisFlash > flashInterval) {
previousMillisFlash = currentMillis;
if (ledState == LOW) ledState = HIGH;
else ledState = LOW;
digitalWrite (ledOutPin, ledState);
}
}