Advertisement
pippero

Untitled

Feb 8th, 2021
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. boolean total_reset=0;
  2. byte premuto = 0; //segnale_memoria
  3. long tt= 0; //tempo_trascorso
  4. long tm= 0; //tempo_memoria
  5. unsigned long o=0;
  6. unsigned long T_media=0;
  7. byte conta = 0;
  8. void setup() {
  9. pinMode(13, OUTPUT);
  10. pinMode(10, INPUT_PULLUP);
  11. Serial.begin(9600);
  12. }
  13. void loop() {
  14.  
  15. if (digitalRead(10) == LOW) {
  16. if (premuto == 0) {
  17. premuto = 1;
  18. tt = millis() - tm;
  19. //Serial.print(tt);
  20. Serial.println ("inizio conteggio");
  21. tm = millis();
  22.  
  23. }
  24. }
  25. if (digitalRead(10) == HIGH) {
  26. if (premuto == 1) {
  27. premuto = 0;
  28. conta = conta + 1;
  29. T_media+=tt;
  30. }
  31. }
  32. if (conta >=3 ) { //conto fino a 3 e faccio la media
  33. T_media=T_media/3;///
  34. Serial.println("fine conteggio: ");
  35. o = millis();
  36. conta =0;
  37. }
  38. if (millis() - o > 10000) {//|| se non aggiorno la media
  39. Serial.println ("reset tempo"); // resetta il sistema
  40. o =millis();
  41. conta =0;
  42. total_reset=1;
  43. Serial.println (total_reset);
  44. }
  45. if (T_media > 1400 || total_reset==1 ) {
  46. digitalWrite(13, HIGH);
  47. Serial.print(" reset ");Serial.println (T_media);
  48. delay(250);
  49. digitalWrite(13, LOW);
  50. total_reset=0;
  51. T_media=0;
  52. }
  53. }
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement