Autor Tema: Portar codigo Serial.available() -> ISR  (Leído 2884 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado CompSystems

  • PIC18
  • ****
  • Mensajes: 488
    • Home Page
Portar codigo Serial.available() -> ISR
« en: 01 de Septiembre de 2016, 15:12:36 »
Hola, el siguiente código pide desde la terminal, varios objetos o datos, un nombre, edad, altura luego recibe el dato cadena, o numero, esto se hace con la función pre-incluida,  Serial.available()  pero deseo ver el código por medio de interrupción y ISR, algún experto en arduino que por favor lo desee portar o en codigo (c,c++,,mikrobasic, etc) para cualquier PIC u otro microcontrolador


Como pueden ver las instrucciones while (Serial.available() == 0) {};  no permiten hacer nada mas hasta que se llene el registro de datos o buffer de transmisión, de ahi mi deseo de ver el código con la lógica de las IRS

Gracias


Código: C++
  1. String myName;   // Declare a String variable to hold your name
  2. int age;         // Declare an Int variable to hold your age
  3. float height;    // Declare a float variable to hold your height
  4. bool loop_flag = false;
  5.  
  6. void setup() {
  7.   Serial.begin(9600);      // turn on Serial Port
  8. }
  9.  
  10. void loop() {
  11.   if (loop_flag == false) {
  12.     Serial.println("Please enter your name > "); // Prompt User for input
  13.     while (Serial.available() == 0) {}           // Wait for user input
  14.     myName = Serial.readString();                // Read user input into myName
  15.     Serial.println("Hello " + myName);                      // Print out nicely formatted output.
  16.  
  17.     Serial.println("How old are you? >");        // Prompt User for input
  18.     while (Serial.available() == 0);
  19.     age = Serial.parseInt();                     // Read user input into age
  20.     Serial.println("you are " + String(age) + " years old,");
  21.  
  22.     Serial.println("How tall are you? >");      // Prompt User for input
  23.     while (Serial.available() == 0);
  24.     height = Serial.parseFloat();               // Read user input into height
  25.     Serial.println("and you are " + String(height) + " feet tall.");
  26.     loop_flag = true;
  27.   }
  28.  
  29. }
« Última modificación: 01 de Septiembre de 2016, 15:18:41 por CompSystems »
Desde Colombia