Go Down

Topic: Converting float into a character (Read 502 times) previous topic - next topic

AWOL

ur help
I wasn't irritated, but I am now.

The handy thing about the World Wide Web is that it comes with handy search tools, and when someone gives you pretty specific search terms, "Bingo!", things happen.
Or maybe not.

OK further hint, sprintf doesn't support %f, but it does support %s.
 Or, go lightweight, don't use sprintf, use strcat instead.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

danArd

#16
Feb 10, 2017, 04:50 pm Last Edit: Feb 10, 2017, 05:50 pm by danArd
Hey guys, i already solved this. That's why im thanking AWOL for this

Quote
I wasn't irritated, but I am now.
Sorry for that :) Chill and wanna drink some beer?


so here sharing my code if ever there's other people here that have same cases with me


Code: [Select]

if(sensorValue != 0){
         int y=0;
         Serial.print("Gas detected");
         while(y != 3){
         static char sensor[10];
         static char sensor1[10];
         static char sensor2[10];
         dtostrf(gas,1,2,sensor);
         dtostrf(smoke,1,2,sensor1);
         dtostrf(co,1,2,sensor2);
         Serial.println("SENDING MESSAGE! ...");
         char finalRead[50];
         sprintf(finalRead,"Gas= %s ppm, smoke = %s ppm, co = %s ppm",sensor,sensor1,sensor2);
         Serial.println(finalRead);
         GSMTEST.sendSMS(PHONE_NUMBER,  finalRead );
         tone(BUZZER,1000);
         delay(3000);
         noTone(BUZZER);
         delay(1000);
         
         y++;
 }
  //send message
  }

 



Thanks everyone and have a nice day ahead!

AWOL

Quote
i wanna
The irritation just keeps growing.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

danArd

Quote
The irritation just keeps growing.
I think you need to drink beer then. toast!  :)

AWOL

Code: [Select]
   static char sensor[10];
         static char sensor1[10];
         static char sensor2[10];

Why "static"?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

danArd

#20
Feb 10, 2017, 06:48 pm Last Edit: Feb 10, 2017, 07:45 pm by danArd
Quote
Why "static"?
will i get any error if i continue to use static in the future? Thanks. Maybe it's quite reliable of storing some data they've said.

econjack

will i get any error if i continue to use static in the future? Thanks. Maybe it's quite reliable of storing some data they've said.
In your understanding, what does the word static do/mean in a data definition?

Go Up