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