-
Notifications
You must be signed in to change notification settings - Fork 0
/
TampereHacklabDoorBell.ino
100 lines (85 loc) · 2.36 KB
/
TampereHacklabDoorBell.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*Tampere Hacklab doorbell ringer
*
* Arduino controlled bell ringer.
* Two tone bell is connected trough
* H-Bridge L293D IC.
*
* Pin 5 goes low when button is pressed.
* Pin 3 and 4 are H-Bridge control lines,
* when either is high, hammer is pulled
* to corresponding bell (high and low tone)
* Pin 6 is H-bridge enable, pull high
*
* Ketturi 2015
*/
//Some defines
const int ButtonPin = 5;
const int LowBellPin = 3;
const int HighBellPin = 4;
const int HBrEnable = 6;
const int HammerTime = 50; //How long hammer solennoid is powered
const int PullBackTime = 5; //Time to pull hammer away from bell
int counter = 0;
void setup() {
//Set pin direction
pinMode(ButtonPin, INPUT_PULLUP);
pinMode(LowBellPin, OUTPUT);
pinMode(HighBellPin, OUTPUT);
pinMode(HBrEnable, OUTPUT);
//Make extra sure everything is low!
digitalWrite(LowBellPin, LOW);
digitalWrite(HighBellPin, LOW);
digitalWrite(HBrEnable, LOW);
}
void loop() {
if (digitalRead(ButtonPin) == LOW) {
if (counter >= 1){ //If button is held down bell will ring faster
DoorBellRing();
}
else { //If button is quiqly pressed it will just ring once
counter = counter+1;
PlayBellSingle();
delay(500);
}
if (digitalRead(ButtonPin) == HIGH){
counter = 0;
}
}
}
void PlayBellSingle(){ //Doorbell single ring
RingHighBell();
delay(500);
RingLowBell();
}
void DoorBellRing(){ // This is just for dull ringing, like old phone
RingHighBell();
delay(25);
RingLowBell();
delay(25);
}
void RingHighBell(){ //pull hammer to high tone bell
digitalWrite(HBrEnable, HIGH);
digitalWrite(HighBellPin, HIGH); //Strike
delay(HammerTime);
digitalWrite(HighBellPin, LOW);
digitalWrite(LowBellPin, HIGH); //PullBack
delay(PullBackTime);
digitalWrite(LowBellPin, LOW);
digitalWrite(HBrEnable, LOW);
}
void RingLowBell(){ //pull hammer to low tone bell
digitalWrite(HBrEnable, HIGH);
digitalWrite(LowBellPin, HIGH); //Strike
delay(HammerTime);
digitalWrite(LowBellPin, LOW);
digitalWrite(HighBellPin, HIGH); //PullBack
delay(PullBackTime);
digitalWrite(HighBellPin, LOW);
digitalWrite(HBrEnable, LOW);
}
/*
* In a world of magnets and miracles
* Our thoughts strayed constantly and without boundary
* The ringing of the division bell had begun
* High Hopes - Pink Floyd
*/