1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| /*
*Le programme attend la saisie d'un caractère 'c' pour afficher une trame de C_maxcar octets.
*Ces octets contiennent les codes ascii consécutifs des caractères '0' à 'C'.
*Cet affichage devrait se produire C_nb_trame fois.
*Alors, le souci :
*Si les instructions Serial.print de la ligne 34 sont commentées, le test de n_trame est ignoré.
*Si ces instructions sont actives, le test est respecté !?!?!?
*/
const int C_maxcar = 20; //256
const unsigned long C_nb_trame = 3 ; // nb envoi de C_nb_trames de C_maxcar byte
const byte C_valeur_octetdedepart = 0x30; // 0x00 ; //0xFB; //0x30 = code de zéro
byte octet[(C_maxcar)] ;
int n_trame = 1;
bool recu = false;
char incomingByte = 'a';
// ***************************************************
void setup() {
Serial.begin(115200); //1024000 230400 768000
delay(500);
// *** initialise un tableau de byte
for (int k = 0; k<= C_maxcar - 1; k++){
octet[k] = k + C_valeur_octetdedepart ; // code ascii de 0123456789:;<=>?@ABC
} // fin for
} // fin setup
// ***************************************************
void loop() {
recu = false;
if ( n_trame <= C_nb_trame ){
//Serial.println("after test n_trame ");Serial.print("C_nb_trame = "); Serial.print(C_nb_trame);
// *** attend un caractère 'c'
while ( !recu ){
if (Serial.available() > 0) {
incomingByte = Serial.read();
if (incomingByte == 'c' ) {
incomingByte = 'z';
recu = true;
} // fin in == 'c'
} // fin Serial.available
} // fin while
Serial.write(octet , C_maxcar);
Serial.flush();
n_trame++;
//Serial.println("after test n_trame ");Serial.print("C_nb_trame = "); Serial.print(C_nb_trame);
} // fin if n_trame
else
{
while (true) ;
} // fin while
} // fin loop |
Partager