View difference between Paste ID: UC4vKh1k and xCknYfe5
SHOW: | | - or go back to the newest paste.
1
#define START 2
2
#define RELAY 3
3
#define MAIN_ON 4
4
#define HEAT_ON 5
5
#define BUZZER  6
6
7
// Tempi saldatura (millisecondi)
8
#define TMIN 2000
9
#define TMAX 20000
10
// Tempi buzzer (millisecondi)
11
#define TON 300
12
#define TOFF 100
13
14
15
unsigned long timeOn = millis(), startTime = 1000;
16
bool risingEdge = false;
17
unsigned int nBuz = 0;
18
19
void setup() {
20
  Serial.begin(9600);
21
  Serial.println("START");
22
  pinMode(START, INPUT_PULLUP);
23
  pinMode(RELAY, OUTPUT);  
24
  pinMode(MAIN_ON, OUTPUT);  
25
  pinMode(HEAT_ON, OUTPUT);  
26
  pinMode(BUZZER, OUTPUT);  
27-
    // Con il potenziometro imposti un tempo compreso tra 2 e 20 secondi
27+
28-
    timeOn = map(analogRead(A0), 0, 1023, 500, 7000);  
28+
29-
    
29+
30
}
31
32
void loop() { 
33
  if((digitalRead(START) == LOW) && (!risingEdge)){  
34
    risingEdge = true;
35
    delay(100);               // Semplice antirimbalzo dello switch
36
    // Con il potenziometro imposti un tempo compreso tra TMIN e TMAX milllisecondi
37
    timeOn = map(analogRead(A0), 0, 1023, TMIN, TMAX);      
38
    startTime = millis();
39
    nBuz = 0;
40
    Serial.print("Start delay timer of ");
41
    Serial.print(timeOn/1000);
42
    Serial.println(" seconds.");    
43
  }
44-
	for(int i=0; i<2; i++){
44+
45-
		digitalWrite(BUZZER, HIGH);
45+
46-
		delay(1000);
46+
47-
		digitalWrite(BUZZER, LOW);
47+
48-
		delay(500);
48+
49-
	}
49+
50
  else{
51
    digitalWrite(RELAY, HIGH);
52-
  // Facciamo in modo che a barra alzata l'uscita venga forzata OFF senza attendere il tempo necessario
52+
53
    if(risingEdge){      
54
      while(nBuz<3){
55
        digitalWrite(BUZZER, HIGH);
56
        delay(TON);
57
        digitalWrite(BUZZER, LOW);
58
        delay(TOFF);
59
        nBuz++;
60
      }      
61
    }
62
  }
63
      
64
  if(digitalRead(START) == HIGH) {  
65
    risingEdge = false;
66
    digitalWrite(RELAY, HIGH);
67
    digitalWrite(HEAT_ON, LOW);
68
    digitalWrite(BUZZER, LOW);    
69
  }
70
}