]> git.piffa.net Git - sketchbook_andrea/blob - advanced_projects/sprintf/sprintf.ino
Structured data types
[sketchbook_andrea] / advanced_projects / sprintf / sprintf.ino
1 /* 
2   sprintf()
3   
4   Uso di sprintf per formattare stringhe di testo
5   Nota: sprintf() non accetta floats
6    
7    */
8 int h = 12;
9 int m = 3;
10 int s = 2;
11
12 void setup() {
13   // initialize serial communications at 9600 bps:
14   Serial.begin(9600); 
15 }
16
17 void loop() {
18   char buffer[17]; // We need a buffer to hold the formatted ouput
19   
20   sprintf(buffer, "Time: %2d:%02d:%02d", h, m, s);  // C sintax
21   
22   Serial.print(buffer);
23   Serial.flush();
24   exit(0);
25 }
26
27