rpitts 0 Posted March 2, 2013 Share Posted March 2, 2013 I'm new to energia development, and I would like an example of how to convert a numeric value to a string for output. Often, the launchpad LCD modules will support output for strings, but I have not found a good way to convert a number into a string for output. I am getting a reading into variable t I want to display on the 2.2 Touch LCD module. My available output command is .text(x,y,string); So I write; float t = dht.readTemperature(); myScreen.Text(10,10,"Temp"); Next I want to output the value to t to the screen. How would you go about doing this? Thanks so much! Ronnie Quote Link to post Share on other sites
roadrunner84 466 Posted March 2, 2013 Share Posted March 2, 2013 One way that seems to work I'd using sprintf. You can quite the result of a string formatting to a string. E.g.: char res[10]; float f; sprintf(res, "%7.3f", f); myScreen.Text(10,10,res); Quote Link to post Share on other sites
energia 485 Posted March 4, 2013 Share Posted March 4, 2013 Serial.println(1.23456, 0) gives "1" Serial.println(1.23456, 2) gives "1.23" Serial.println(1.23456, 4) gives "1.2346" See the Serial print class description here: http://arduino.cc/en/Serial/Print The MSP430 does not have a floating point unit and using floating points will add about 4k of floating point emulation code to your sketch plus it will make things unnecessarily slow. See Rei Vilo's example in the DHT library posted here for how to avoid using floats in your code http://forum.43oh.com/topic/2239-solved-dht22-temp-rh-one-wire-sensor-on-energia/#entry19474 Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.