Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. *Declaracion de variables*/
  2. int ledPin = 13; // Pines de salida
  3. int data_num;
  4. /*Vector de 3 elmentos, posicion 0, posicion1 y posicion2*/
  5. char byteRead[20];
  6.  
  7.  
  8. /*Funcion SETUP se ejecuta una sóla vez*/
  9. void setup()
  10. {
  11. Serial.begin(9600); // Configuracion de la velocidad serial
  12. /*Configuracion de los pines de salida mediante un ciclo for*/
  13. pinMode(ledPin, OUTPUT);
  14. /*Mensaje de Bienvenida en el puerto serial*/
  15. }
  16.  
  17.  
  18. /*Funcion LOOP, se repite indefinidamente*/
  19. void loop()
  20. {
  21. digitalWrite(ledPin, HIGH);
  22. Serial.write("\nInicializando...\n");delay(10);
  23. Serial.write("Ejercicio HeTPro para control de datos por serial\n");delay(10);
  24. Serial.write("Particularmente con diferentes longitudes \n");delay(10);
  25.  
  26. Serial.write("Dispositivo: RSX2584\n");delay(10);
  27. Serial.write("Nombre de usuario:\n");delay(10);
  28. leer_comparar("Hector", "Usuario");
  29. Serial.write("Password:\n");delay(10);
  30. leer_comparar("1234", "Password");
  31. Serial.write("Comando:\n");delay(100);
  32. leer_comparar("MOV35M1", "Comando");
  33. Serial.write("Iniciando ciclo de depuracion del sistema.\n");
  34. Serial.write("Procesando");
  35. delay(100);
  36.  
  37. for(int i=0 ; i<=data_num ; i++ ){
  38. Serial.write(".");
  39. delay(500);
  40. }
  41. Serial.write("\nTiempo de proceso: ");
  42. Serial.print(millis());
  43. Serial.write("ms.");
  44. while(1);
  45. }
  46.  
  47.  
  48.  
  49.  
  50.  
  51. void leer_comparar(char byteRead_comp[20], char caso_lectura[20] ){
  52. while(Serial.available()==0);delay(10);
  53. data_num=Serial.available();
  54. Serial.write("Caracteres leidos: "); Serial.println(data_num);delay(10);
  55. for(int i=0 ; i<data_num ; i++ ){
  56. byteRead[i] = Serial.read();Serial.write(".");
  57. }
  58. delay(10);
  59. Serial.write(byteRead_comp);
  60. if (strcmp(byteRead_comp, byteRead) == 0){
  61. Serial.print("\n");
  62. Serial.write(caso_lectura);
  63. Serial.print(": ");
  64. Serial.write(byteRead_comp);
  65. Serial.print("\n");
  66. }
  67. else{
  68. Serial.println("\r\nVALOR NO VALIDO REINICIE EL DISPOSITIVO");
  69. while(1);
  70. }
  71. memset(byteRead,0,20);
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement