Advertisement
Guest User

Untitled

a guest
Aug 27th, 2019
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. char msg_buffer[60];
  2. float temperature = 10.5;
  3.  
  4. void setup()
  5. {
  6.  Serial.begin(9600);
  7.  char temp_str[15] = {0};
  8.  dtostrf(temperature, 4, 1, temp_str);
  9.  char *space = strchr(temp_str, ' ');
  10.  if (space != NULL) {
  11.   *space = '\0';
  12.  }
  13.  sprintf(msg_buffer, "Temperature: %s", temp_str);
  14.  Serial.println(msg_buffer);
  15.  pinMode(13, OUTPUT);
  16. }
  17.  
  18. void loop() {}
  19.  
  20.  
  21. /* alternative setup() */
  22. void setup() {
  23.  Serial.begin(9600);
  24.  //create String object from float with 1 decimal place
  25.  //will be heap-allocated
  26.  String output = "Temperature " + String(temperature, 1);
  27.  Serial.println(output);
  28.  pinMode(13, OUTPUT);  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement