0
Offline
Newbie
Karma: 0
Posts: 45
Arduino rocks
|
 |
« on: June 04, 2010, 10:36:09 am » |
bonjour
je souhaiterais faire un tableau de ce type à l'aide d'un terminal :
Vitesse | Courant consigne: 10 | consigne: 20 mesure: 20 | mesure: 60 ... et les valeurs sont bien sur variables merci d'avance!
|
|
|
|
« Last Edit: June 05, 2010, 04:39:25 am by freeman32 »
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 37
Arduino rocks
|
 |
« Reply #1 on: June 05, 2010, 02:35:00 pm » |
Essayes un truc comme ça char ascii[32]; sprintf(ascii,"consigne: %d \t| consigne: %d",consigneV,consigneC); Serial.print(ascii);
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 45
Arduino rocks
|
 |
« Reply #2 on: June 09, 2010, 03:37:23 am » |
en langage arduino sa donnerai quoi??
|
|
|
|
|
Logged
|
|
|
|
|
Ales
Offline
Edison Member
Karma: 8
Posts: 1803
Do or DIY
|
 |
« Reply #3 on: June 09, 2010, 10:56:57 am » |
La même chose ...
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 45
Arduino rocks
|
 |
« Reply #4 on: June 10, 2010, 03:19:45 am » |
hein mais comment il est possible de faire un sprintf avec arduino??
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 45
Arduino rocks
|
 |
« Reply #5 on: June 10, 2010, 07:36:08 am » |
bon j'ai essayer en utilisant la biblio stdio sa marche mais seulement une fois sur 10... quelqu'un aura pas une autre solution ?
|
|
|
|
|
Logged
|
|
|
|
|
Celtic Kingdom
Offline
Sr. Member
Karma: 2
Posts: 455
hard oui no!!!
|
 |
« Reply #6 on: June 10, 2010, 08:38:41 am » |
A priori les valeurs type float ne passent pas dans le sprintf avec stdio (?). Une solution serait de faire passer les valeur de float en ascii avec sprintf(ascii,... J'ai lu cela quelque part sur le forum UK, je ne sais plus où..
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 20
Arduino rocks
|
 |
« Reply #7 on: June 10, 2010, 01:12:09 pm » |
Pour ma part j'utilise ce code pour afficher des nombres décimaux sur mon lcd. (ce n'est pas de moi) Voila ce que ça donne pour une écriture sur le port série : char buf[12]; double var=1.11;
void setup() { Serial.begin(9600); }
void loop() { PrintDouble(var,2); }
void PrintDouble( double val, byte precision){
if(val < 0.0){ Serial.println('-'); val = -val; }
Serial.print(itoa(val,buf,10)); //prints the int part if( precision > 0) { Serial.print("."); // print the decimal point unsigned long frac; unsigned long mult = 1; byte padding = precision -1; while(precision--) mult *=10;
if(val >= 0) frac = (val - int(val)) * mult; else frac = (int(val)- val ) * mult; unsigned long frac1 = frac; while( frac1 /= 10 ) padding--; while( padding--) Serial.print("0"); Serial.println(itoa(frac,buf,10)) ; } }
Si tu as des questions , n'hésite pas
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 37
Arduino rocks
|
 |
« Reply #8 on: June 10, 2010, 02:04:22 pm » |
Bein chez moi ça marche directement sans include ni rien void setup() { Serial.begin(9600); }
void loop() { int val = 18 ; char buffer[54]; sprintf( buffer , "Je veux afficher %04d" , val ); Serial.println( buffer ); delay( 1000 ); }
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 20
Arduino rocks
|
 |
« Reply #9 on: June 10, 2010, 02:58:04 pm » |
Perso j'ai pas tester ta maniere, je devrais peut etre le faire avec la routine pour l'affichage de float pour mon lcd 
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 45
Arduino rocks
|
 |
« Reply #10 on: June 11, 2010, 03:07:42 am » |
le probleme c'est que sa bug souvent quand je fais appel au sprintf je ne sais vraiment pas pourquoi 
|
|
|
|
« Last Edit: June 11, 2010, 03:10:19 am by freeman32 »
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 45
Arduino rocks
|
 |
« Reply #11 on: June 11, 2010, 03:20:51 am » |
voici un de mes programme de test #define HOME 1
char ascii[32]; char ascii1[32]; int consigneV,consigneC,consigneV2,consigneC2;
void setup() { Serial.begin(9600); consigneV=20; consigneC=30; consigneV2=60; consigneC2=70; }
void loop() { Serial.print(HOME,BYTE); sprintf(ascii,"consigne: %d \t| consigne: %d \n",consigneV,consigneC); sprintf(ascii1,"consigne2: %d \t| consigne2: %d",consigneV2,consigneC2); Serial.print(ascii); }
|
|
|
|
« Last Edit: June 11, 2010, 03:21:48 am by freeman32 »
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 45
Arduino rocks
|
 |
« Reply #12 on: June 11, 2010, 05:12:20 am » |
autrement voici mon tableau fait a l'arrache : Serial.print(HOME,BYTE); Serial.print("vitesse");Serial.print(" | ");Serial.println("courant"); Serial.print("consigne(cv): ");Serial.print(ConsigneVitesse, DEC);Serial.print("\t| ");Serial.print("consigne(cc): ");Serial.println(ConsigneCourant, DEC); Serial.print("Mesure(en V): ");Serial.print(MesureVitesse, DEC);Serial.print("\t| ");Serial.print("Mesure(en A): ");Serial.println(MesureCourant, DEC); Serial.print("Kp(kpv): ");Serial.print(chiffreKpv, DEC);Serial.print("\t | ");Serial.print("Kp(kpc): ");Serial.println(chiffreKpc, DEC); Serial.print("Ki(kiv): "); Serial.print(chiffreKiv, DEC);Serial.print("\t | "); Serial.print("Ki(kic): "); Serial.println(chiffreKic, DEC); Serial.print("Kd(kdv): "); Serial.print(chiffreKdv, DEC);Serial.print("\t | ");Serial.print("Kd(kdc): "); Serial.println(chiffreKdc, DEC); Serial.print("AUTO/MANUAL(1/0)(amv): ");Serial.print(chiffreAmv);Serial.print("\t| ");Serial.print("AUTO/MANUAL(1/0)(amc): ");Serial.println(chiffreAmc); il marche mais j'ai souvent des bugs :-[
|
|
|
|
|
Logged
|
|
|
|
|
Geneva
Offline
Faraday Member
Karma: 22
Posts: 2894
Yoplait... le pt'it suisse
|
 |
« Reply #13 on: January 09, 2011, 04:47:07 am » |
La fonction dtostrf() permet de passer un float dans un tableau de char. char tableau[8]; dtostrf(valFloat, 7, 5, tableau); Serial.print(tableau)
|
|
|
|
« Last Edit: January 09, 2011, 04:47:41 am by jfs »
|
Logged
|
MacBook intel core 2 duo os X snow Leopard 10.6 eMac PPc G4 os X Leopard 10.5 powerbook G4 os X Leopard 10.5 imac PPC G3 os X Panther 10.3.9 Arduino Diecimila Arduino Mega Arduino Standalone Arduino 1307.04 
|
|
|
|
|