Advertisement
pippero

Untitled

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