Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- boolean flag = 0;
- boolean total_reset = 1;
- byte premuto = 0; //segnale_memoria
- long tt = 0; //tempo_trascorso
- long tm = 0; //tempo_memoria
- unsigned long T_pertenza = 0; // tempo avvio macchina
- unsigned long o = 0;
- float T_media = 0.0;
- byte conta = 0;
- int sensorValue = 0;
- void setup() {
- pinMode(13, OUTPUT);
- pinMode(A5, INPUT);
- Serial.begin(9600);
- Serial.println (F(" xxxxx "));
- }
- void loop() {
- sensorValue = analogRead(A5);
- if (sensorValue >= 500 ) {
- o = millis();
- if (premuto == 0) {
- premuto = 1;
- tt = millis() - tm;
- Serial.print (F(" premuto "));
- Serial.println (conta);
- tm = millis();
- }
- }
- if (sensorValue < 500) {
- if (premuto == 1) {
- premuto = 0;
- conta = conta + 1;
- T_media += tt;
- }
- }
- //||se total_reset == calcolo il tempo delle pressioni
- if (total_reset == 0) {
- //||se non aggiorno sensorValue resetta il sistema
- if (millis() - o > 10000) {
- Serial.println (F("reset tempo"));
- total_reset = 1;// avvio procedura reset
- }
- //conto fino a 5 e faccio la media
- if (conta >= 5 && premuto == 0) {
- conta = 0;
- Serial.print (F("tt ")); Serial.println (tt );
- Serial.print (F("T_media "));
- Serial.println (T_media / 5 );
- Serial.println(F(" controllo"));
- //dentro a conta >= 5 valuto il tempo T_media / 2
- if (T_media / 5 < 2000 ) { //se vera
- total_reset = 1;// avvio procedura reset
- }
- else {
- Serial.println(F(" no azioni"));
- }
- T_media = 0.0;
- }
- }
- if (total_reset == 1 ) {
- if (flag == 0 ) {
- T_media = 0.0;
- conta = 0;
- T_pertenza = millis();
- Serial.println(F(" reset HIGH"));
- digitalWrite(13, HIGH);
- delay(1000);
- Serial.println(F(" reset LOW"));
- digitalWrite(13, LOW);
- flag = 1;
- }
- // tempo di avvio da reset
- if (millis() - T_pertenza > 30000) {
- Serial.println(F(" avvio"));
- flag = 0;
- total_reset = 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement