Guest User

Untitled

a guest
Nov 21st, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. #include <LiquidCrystal.h>
  2. #include <SD.h>
  3.  
  4. LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
  5.  
  6. int buttons;
  7. File myFile;
  8. //name of the file
  9. char nombrefichero[12];
  10. int i = 1;
  11. int exist = LOW ;
  12.  
  13. void setup() {
  14. Serial.begin(9600);
  15. //check the sd card adapter
  16. Serial.print("Iniciando SD ...");
  17. if (!SD.begin(53)) {
  18. Serial.println("No se pudo inicializar");
  19. return;
  20. }
  21. Serial.println("inicializacion exitosa");
  22. }
  23.  
  24. void loop() {
  25. // use the buttons of the lcd keypand shield in analog 0
  26. buttons = analogRead(0);
  27.  
  28. //button right
  29. if(buttons < 50){
  30. count ++;
  31. nuevo();
  32. }
  33.  
  34. //button select
  35. if(buttons < 790){
  36. capturar();
  37. }
  38.  
  39. }
  40.  
  41. void capturar(){
  42. myFile = SD.open(nombrefichero, FILE_WRITE);//abrimos el archivo
  43.  
  44. if (myFile) {
  45. Serial.print("Escribiendo SD: ");
  46. int sensor1 = analogRead(0);
  47. int sensor2 = analogRead(1);
  48. int sensor3 = analogRead(2);
  49. myFile.print(millis());
  50. myFile.print(",");
  51. myFile.print(sensor1);
  52. myFile.print(",");
  53. myFile.print(sensor2);
  54. myFile.print(",");
  55. myFile.println(sensor3);
  56.  
  57. myFile.close(); //cerramos el archivo
  58.  
  59. Serial.print("Tiempo(ms)=");
  60. Serial.print(millis());
  61. Serial.print(",sensor1=");
  62. Serial.print(sensor1);
  63. Serial.print(",sensor2=");
  64. Serial.print(sensor2);
  65. Serial.print(",sensor3=");
  66. Serial.println(sensor3);
  67.  
  68.  
  69. } else {
  70. // if the file didn't open, print an error:
  71. Serial.println("Error al abrir el archivo");
  72. }
  73. delay(1000);
  74. }
  75.  
  76. void nuevo(){
  77.  
  78. while (exist == LOW)
  79. {
  80. sprintf(nombrefichero, "M%d.txt",i); //generate autoincrement number of
  81. file
  82.  
  83. if(SD.exists(nombrefichero))
  84. {
  85. i = i+1;
  86. myFile = SD.open(nombrefichero, FILE_WRITE);
  87. if (myFile) {
  88. Serial.println("Archivo nuevo, Escribiendo encabezado(fila 1)");
  89. myFile.println("Tiempo(ms),Sensor1,Sensor2,Sensor3");
  90.  
  91. myFile.close();
  92.  
  93. } else {
  94. exist = HIGH;
  95. Serial.println("Error creando el archivo");
  96. }
  97. }
  98.  
  99. }
  100. }
  101.  
  102. void nuevo(){
  103.  
  104. while (exist == LOW)
  105. {
  106. sprintf(nombrefichero, "M%d.txt",i);
  107. if(SD.exists(nombrefichero))
  108. {
  109. i = i+1;
  110. myFile = SD.open(nombrefichero, FILE_WRITE);
  111. if (myFile) {
  112. Serial.println("Archivo nuevo, Escribiendo encabezado(fila 1)");
  113. myFile.println("Tiempo(ms),Sensor1,Sensor2,Sensor3");
  114.  
  115. myFile.close();
  116.  
  117. } else {
  118. exist = HIGH;
  119. Serial.println("Error creando el archivo");
  120. }
  121. }
  122.  
  123. }
  124. }
Add Comment
Please, Sign In to add comment