Advertisement
pippero

Untitled

Feb 14th, 2021
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. boolean flag = 0;
  2. boolean total_reset = 0;
  3. byte premuto = 0; //segnale_memoria
  4. long tt = 0; //tempo_trascorso
  5. long tm = 0; //tempo_memoria
  6. unsigned long T_pertenza = 0; // tempo avvio macchina
  7. unsigned long o = 0;
  8. float T_media = 3000;
  9. byte conta = 0;
  10. int sensorValue = 0;
  11. void setup() {
  12. pinMode(13, OUTPUT);
  13. digitalWrite(13, HIGH);
  14. delay(1000);
  15. digitalWrite(13, LOW);
  16. pinMode(A5, INPUT);
  17. Serial.begin(9600);
  18. }
  19. void loop() {
  20. sensorValue = analogRead(A5);
  21. if (sensorValue >= 500 ) {
  22. o = millis();
  23. if (premuto == 0) {
  24. premuto = 1;
  25. tt = millis() - tm;
  26. Serial.println (" premuto ");
  27. tm = millis();
  28. }
  29. }
  30. if (sensorValue < 500) {
  31. if (premuto == 1) {
  32. premuto = 0;
  33. conta = conta + 1;
  34. T_media += tt;
  35. }
  36. }
  37. if (total_reset == 0) {
  38. flag = 0;
  39. //||se non aggiorno sensorValue resetta il sistema
  40. if (millis() - o > 10000) {
  41. Serial.println ("reset tempo");
  42. T_media = 0;
  43. conta = 0;
  44.  
  45. total_reset = 1;
  46. }
  47. //conto fino a 3 e faccio la media
  48. if (conta >= 10 && premuto == 0) {
  49. Serial.print ("tt "); Serial.println (tt );
  50. Serial.print ("T_media "); Serial.println (T_media / 10 );
  51. conta = 0;
  52. Serial.println(" controllo");
  53. //dentro a conta >= 2 valuto il tempo T_media / 2
  54. if (T_media / 10 < 2000 ) { //se vera
  55. total_reset = 1;
  56. }
  57. else {
  58. Serial.println(" no azioni");
  59. }
  60. T_media = 0;
  61. }
  62. }
  63. if (total_reset == 1 ) {
  64. if (flag == 0 ) {
  65. T_pertenza = millis();
  66. Serial.println(" reset HIGH");
  67. digitalWrite(13, HIGH);
  68. delay(1000);
  69. Serial.println(" reset LOW");
  70. digitalWrite(13, LOW);
  71. flag = 1;
  72. }
  73.  
  74. if (millis() - T_pertenza > 30000) {
  75. Serial.println(" avvio");
  76. total_reset = 0;
  77. }
  78.  
  79.  
  80. T_media = 0;
  81. conta = 0;
  82. }
  83.  
  84. }
  85.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement