int total = 0;
for (int i = 0; i < 10; i++) {
total = total + analogRead(sensorPin);
- delay(2); // Pausa per assestare il senstore
+ delay(2); // Pausa per assestare il sensore
}
return(total / 10); // Valore medio
+ /* Nota: i microcontroller non sono bravi a fare le divisioni,
+ sarebbe piu' efficiente ottenere 8 valori e fare uno shift dx. di 3 bit
+ total = total >> 3 ;
+Vedi: https://www.arduino.cc/en/Reference/Bitshift
+ */
}