Advertisement
Ioter

Untitled

Oct 26th, 2020 (edited)
2,529
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. /*Arduino*/
  2. /*------------------------------------------------------------*/
  3. int randomN;
  4. char id = T;
  5. int valor;
  6. void setup()
  7. {
  8.   Serial.begin(9600);
  9. }
  10.  
  11. void loop()
  12. {
  13.   randomN = random(100);
  14.   //valor = 20;
  15.   //Serial.print("konnichiwa sekai\r");
  16.   //Serial.print(id);
  17.   Serial.print(randomN);
  18.   Serial.print("\r");//Indica el final del Mensaje
  19.   delay(1000);
  20. }
  21.  
  22. /*ESP8266*/
  23. /*------------------------------------------------------------*/
  24. #include "LiquidCrystal_I2C.h"
  25. #include "Wire.h"
  26. LiquidCrystal_I2C lcd(0x27, 20, 4);
  27. char buff [50];
  28. volatile byte indx;
  29. char c = NULL;
  30.  
  31. void setup()
  32. {
  33.   Serial.begin(9600);
  34.   lcd.init();
  35.   lcd.backlight();
  36.   lcd.clear();
  37.   indx = 0;
  38. }
  39.  
  40. void loop()
  41. {
  42.   if (Serial.available() > 0)
  43.   {
  44.     c = Serial.read();//Le un caracter del serial
  45.     if (indx < sizeof buff)
  46.     {
  47.       if (c == '\r') //Final del Mensaje
  48.       {
  49.         lcd.clear();
  50.         lcd.print(buff);
  51.         delay(1000);
  52.         indx= 0; //Regresa la posicion a cero
  53.         //lcd.clear();
  54.       }
  55.       else
  56.       {
  57.         buff[indx] = c; //Guarda el dato en el buffer
  58.         indx++;
  59.       }
  60.     }//
  61.   }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement