Fix buzzer volume

This commit is contained in:
Pascal Engélibert 2022-09-10 19:13:23 +02:00
parent c43e7d379f
commit 43921bc4f2
Signed by: tuxmain
GPG key ID: 3504BC6D362F7DCA
4 changed files with 92 additions and 92 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
/alarmclock/alarmclock-backups /alarmclock/alarmclock-backups
/alarmclock/#auto_saved_files#

View file

@ -12,7 +12,9 @@ Arduino alarm clock with binary matrix LED display and capacitive touch buttons.
## Notes ## Notes
A NE555 is used for generating a high-frequency PWM signal, feeding one 74HC's "Output Enable" port. This is because otherwise the LEDs are too bright, and playing with the serial signal to reduce brightness is not fast enough (it produces a perceptible blinking). Also, using the Arduino's internal PWM causes the serial transmission to behave erratically. And of course, as 74HC uses logical gates, it needs a binary (PWM) signal, not analog. A NE555 is used for generating a high-frequency PWM signal, feeding one 74HC's "Output Enable" port. This is because otherwise the LEDs are too bright, and playing with the serial signal to reduce brightness is not fast enough (it produces a perceptible blinking). Also, using the Arduino's internal PWM causes the serial transmission to behave erratically (because of timers interfering with transmission, and because frequency is too low). And of course, as 74HC uses logical gates, it needs a binary (PWM) signal, not analog.
D5 is used for the buzzer because its PWM frequency is greater than other pins.
## TODO ## TODO
@ -21,11 +23,11 @@ A NE555 is used for generating a high-frequency PWM signal, feeding one 74HC's "
* multiple alarms * multiple alarms
* date (at least weekday) * date (at least weekday)
* connection with online timetable? * connection with online timetable?
* progressive alarm ringing
* capacitive sensing causes LED matrix to flicker * capacitive sensing causes LED matrix to flicker
* better calibrate display PWM * better calibrate display PWM
* light sensor for display PWM * light sensor for display PWM
* save alarm time & automatically retrieve time from network or RF * save alarm time & automatically retrieve time from network or RF
* alarm auto-stop
## License ## License

View file

@ -892,6 +892,10 @@
(stroke (width 0) (type default) (color 0 0 0 0)) (stroke (width 0) (type default) (color 0 0 0 0))
(uuid 08281721-14a0-4149-865b-863b1bf2e43a) (uuid 08281721-14a0-4149-865b-863b1bf2e43a)
) )
(wire (pts (xy 120.65 110.49) (xy 128.27 110.49))
(stroke (width 0) (type default) (color 0 0 0 0))
(uuid 0fd53afe-ca9b-43d3-87d6-ddb18a2e7200)
)
(wire (pts (xy 93.98 69.85) (xy 93.98 57.15)) (wire (pts (xy 93.98 69.85) (xy 93.98 57.15))
(stroke (width 0) (type default) (color 0 0 0 0)) (stroke (width 0) (type default) (color 0 0 0 0))
(uuid 0fe258fe-04e7-4d8c-98a7-53e1ac5d7856) (uuid 0fe258fe-04e7-4d8c-98a7-53e1ac5d7856)
@ -912,10 +916,18 @@
(stroke (width 0) (type default) (color 0 0 0 0)) (stroke (width 0) (type default) (color 0 0 0 0))
(uuid 173ad493-5ce5-4a7c-9e85-c849dbfd0749) (uuid 173ad493-5ce5-4a7c-9e85-c849dbfd0749)
) )
(wire (pts (xy 142.24 93.98) (xy 128.27 93.98))
(stroke (width 0) (type default) (color 0 0 0 0))
(uuid 1afe9909-b731-4dbf-bab6-fd1717ce6afa)
)
(wire (pts (xy 158.75 140.97) (xy 158.75 146.05)) (wire (pts (xy 158.75 140.97) (xy 158.75 146.05))
(stroke (width 0) (type default) (color 0 0 0 0)) (stroke (width 0) (type default) (color 0 0 0 0))
(uuid 1decbc96-4d09-470d-90b5-8007e552c881) (uuid 1decbc96-4d09-470d-90b5-8007e552c881)
) )
(wire (pts (xy 128.27 110.49) (xy 128.27 93.98))
(stroke (width 0) (type default) (color 0 0 0 0))
(uuid 1ef89d54-61f0-4077-b73e-b476bc4d0e2e)
)
(wire (pts (xy 139.7 109.22) (xy 139.7 135.89)) (wire (pts (xy 139.7 109.22) (xy 139.7 135.89))
(stroke (width 0) (type default) (color 0 0 0 0)) (stroke (width 0) (type default) (color 0 0 0 0))
(uuid 20e1e8ee-99ab-4e44-8fc5-a42f193f3f37) (uuid 20e1e8ee-99ab-4e44-8fc5-a42f193f3f37)
@ -960,13 +972,17 @@
(stroke (width 0) (type default) (color 0 0 0 0)) (stroke (width 0) (type default) (color 0 0 0 0))
(uuid 3c1e82c9-fea0-48a6-845c-322736992719) (uuid 3c1e82c9-fea0-48a6-845c-322736992719)
) )
(wire (pts (xy 142.24 91.44) (xy 124.46 91.44))
(stroke (width 0) (type default) (color 0 0 0 0))
(uuid 3c24102b-a8b7-4b88-a099-e60b160231a2)
)
(wire (pts (xy 137.16 106.68) (xy 142.24 106.68)) (wire (pts (xy 137.16 106.68) (xy 142.24 106.68))
(stroke (width 0) (type default) (color 0 0 0 0)) (stroke (width 0) (type default) (color 0 0 0 0))
(uuid 3d19638c-f994-4afd-9452-69496fc15ed5) (uuid 3d19638c-f994-4afd-9452-69496fc15ed5)
) )
(wire (pts (xy 119.38 101.6) (xy 142.24 101.6)) (wire (pts (xy 124.46 91.44) (xy 124.46 93.98))
(stroke (width 0) (type default) (color 0 0 0 0)) (stroke (width 0) (type default) (color 0 0 0 0))
(uuid 4f96485b-79c9-4e23-ad0f-282e3d835b81) (uuid 4a84256a-c887-4354-b4d7-cae97ae91d33)
) )
(wire (pts (xy 129.54 140.97) (xy 137.16 140.97)) (wire (pts (xy 129.54 140.97) (xy 137.16 140.97))
(stroke (width 0) (type default) (color 0 0 0 0)) (stroke (width 0) (type default) (color 0 0 0 0))
@ -976,10 +992,6 @@
(stroke (width 0) (type default) (color 0 0 0 0)) (stroke (width 0) (type default) (color 0 0 0 0))
(uuid 57ffaaf0-e14e-442c-8cce-905d6abfe55e) (uuid 57ffaaf0-e14e-442c-8cce-905d6abfe55e)
) )
(wire (pts (xy 119.38 124.46) (xy 119.38 101.6))
(stroke (width 0) (type default) (color 0 0 0 0))
(uuid 5a725437-1a79-4644-8f94-f36106378c55)
)
(wire (pts (xy 91.44 67.31) (xy 110.49 67.31)) (wire (pts (xy 91.44 67.31) (xy 110.49 67.31))
(stroke (width 0) (type default) (color 0 0 0 0)) (stroke (width 0) (type default) (color 0 0 0 0))
(uuid 5db1cc82-cede-4a46-a004-1347419de76f) (uuid 5db1cc82-cede-4a46-a004-1347419de76f)
@ -988,10 +1000,6 @@
(stroke (width 0) (type default) (color 0 0 0 0)) (stroke (width 0) (type default) (color 0 0 0 0))
(uuid 5ec3842a-4522-4b00-b3e2-1d685d61625c) (uuid 5ec3842a-4522-4b00-b3e2-1d685d61625c)
) )
(wire (pts (xy 105.41 93.98) (xy 142.24 93.98))
(stroke (width 0) (type default) (color 0 0 0 0))
(uuid 5ed8222e-e54b-48f9-8b21-6489d05a2cae)
)
(wire (pts (xy 68.58 154.94) (xy 68.58 160.02)) (wire (pts (xy 68.58 154.94) (xy 68.58 160.02))
(stroke (width 0) (type default) (color 0 0 0 0)) (stroke (width 0) (type default) (color 0 0 0 0))
(uuid 5f722d5d-d544-49c2-9089-731af724b30c) (uuid 5f722d5d-d544-49c2-9089-731af724b30c)
@ -1060,6 +1068,10 @@
(stroke (width 0) (type default) (color 0 0 0 0)) (stroke (width 0) (type default) (color 0 0 0 0))
(uuid 92ef4347-551d-4e63-ba76-1bc041c8c835) (uuid 92ef4347-551d-4e63-ba76-1bc041c8c835)
) )
(wire (pts (xy 124.46 93.98) (xy 105.41 93.98))
(stroke (width 0) (type default) (color 0 0 0 0))
(uuid 94d1fcc6-7fe6-4f3b-8117-3935151bbd2d)
)
(wire (pts (xy 91.44 74.93) (xy 107.95 74.93)) (wire (pts (xy 91.44 74.93) (xy 107.95 74.93))
(stroke (width 0) (type default) (color 0 0 0 0)) (stroke (width 0) (type default) (color 0 0 0 0))
(uuid 99907f80-05e8-4b74-bbeb-1789e8268128) (uuid 99907f80-05e8-4b74-bbeb-1789e8268128)
@ -1176,10 +1188,6 @@
(stroke (width 0) (type default) (color 0 0 0 0)) (stroke (width 0) (type default) (color 0 0 0 0))
(uuid f525b1ed-0f0e-49eb-a7ed-1eac8bf0aa11) (uuid f525b1ed-0f0e-49eb-a7ed-1eac8bf0aa11)
) )
(wire (pts (xy 116.84 124.46) (xy 119.38 124.46))
(stroke (width 0) (type default) (color 0 0 0 0))
(uuid f5a04c40-1b7b-43b8-b9cf-7da9cbf65b8e)
)
(wire (pts (xy 105.41 101.6) (xy 105.41 93.98)) (wire (pts (xy 105.41 101.6) (xy 105.41 93.98))
(stroke (width 0) (type default) (color 0 0 0 0)) (stroke (width 0) (type default) (color 0 0 0 0))
(uuid f82b5d62-ec47-4fef-acb0-d9bee638cb5c) (uuid f82b5d62-ec47-4fef-acb0-d9bee638cb5c)
@ -1231,21 +1239,6 @@
) )
) )
(symbol (lib_id "Device:R") (at 113.03 124.46 270) (unit 1)
(in_bom yes) (on_board yes) (fields_autoplaced)
(uuid 0d696145-2ec2-4bef-994b-9f1c8758cd4d)
(property "Reference" "R1" (id 0) (at 113.03 118.11 90))
(property "Value" "161Ω" (id 1) (at 113.03 120.65 90))
(property "Footprint" "" (id 2) (at 113.03 122.682 90)
(effects (font (size 1.27 1.27)) hide)
)
(property "Datasheet" "~" (id 3) (at 113.03 124.46 0)
(effects (font (size 1.27 1.27)) hide)
)
(pin "1" (uuid 8a7575e3-608b-494f-a588-28cd13690535))
(pin "2" (uuid 71fcda25-4b0d-41ed-ac73-b065872a22d5))
)
(symbol (lib_id "power:GND") (at 91.44 154.94 0) (unit 1) (symbol (lib_id "power:GND") (at 91.44 154.94 0) (unit 1)
(in_bom yes) (on_board yes) (in_bom yes) (on_board yes)
(uuid 10b43c5e-ec4b-4d13-a53d-a901fb067720) (uuid 10b43c5e-ec4b-4d13-a53d-a901fb067720)
@ -1308,15 +1301,15 @@
(pin "1" (uuid eb243f0b-1352-421f-bec7-8db4af5d0c2e)) (pin "1" (uuid eb243f0b-1352-421f-bec7-8db4af5d0c2e))
) )
(symbol (lib_id "Device:Buzzer") (at 106.68 127 0) (mirror y) (unit 1) (symbol (lib_id "Device:Buzzer") (at 118.11 113.03 0) (mirror y) (unit 1)
(in_bom yes) (on_board yes) (fields_autoplaced) (in_bom yes) (on_board yes) (fields_autoplaced)
(uuid 20e06040-d647-4f00-8cdf-985064ab739e) (uuid 20e06040-d647-4f00-8cdf-985064ab739e)
(property "Reference" "BZ1" (id 0) (at 105.918 118.11 0)) (property "Reference" "BZ1" (id 0) (at 117.348 104.14 0))
(property "Value" "Buzzer" (id 1) (at 105.918 120.65 0)) (property "Value" "Buzzer" (id 1) (at 117.348 106.68 0))
(property "Footprint" "" (id 2) (at 107.315 124.46 90) (property "Footprint" "" (id 2) (at 118.745 110.49 90)
(effects (font (size 1.27 1.27)) hide) (effects (font (size 1.27 1.27)) hide)
) )
(property "Datasheet" "~" (id 3) (at 107.315 124.46 90) (property "Datasheet" "~" (id 3) (at 118.745 110.49 90)
(effects (font (size 1.27 1.27)) hide) (effects (font (size 1.27 1.27)) hide)
) )
(pin "1" (uuid 64d506ab-e1f1-4fa6-af2f-d32fa7b7233a)) (pin "1" (uuid 64d506ab-e1f1-4fa6-af2f-d32fa7b7233a))
@ -1543,17 +1536,17 @@
(pin "9" (uuid 8c6fd9d1-9190-4632-93bc-f8655686f38b)) (pin "9" (uuid 8c6fd9d1-9190-4632-93bc-f8655686f38b))
) )
(symbol (lib_id "power:GND") (at 109.22 129.54 0) (unit 1) (symbol (lib_id "power:GND") (at 120.65 115.57 0) (unit 1)
(in_bom yes) (on_board yes) (in_bom yes) (on_board yes)
(uuid b7ec45b7-309e-49b5-84d7-3c2491b225fa) (uuid b7ec45b7-309e-49b5-84d7-3c2491b225fa)
(property "Reference" "#PWR?" (id 0) (at 109.22 135.89 0) (property "Reference" "#PWR?" (id 0) (at 120.65 121.92 0)
(effects (font (size 1.27 1.27)) hide) (effects (font (size 1.27 1.27)) hide)
) )
(property "Value" "GND" (id 1) (at 109.22 133.35 0)) (property "Value" "GND" (id 1) (at 120.65 119.38 0))
(property "Footprint" "" (id 2) (at 109.22 129.54 0) (property "Footprint" "" (id 2) (at 120.65 115.57 0)
(effects (font (size 1.27 1.27)) hide) (effects (font (size 1.27 1.27)) hide)
) )
(property "Datasheet" "" (id 3) (at 109.22 129.54 0) (property "Datasheet" "" (id 3) (at 120.65 115.57 0)
(effects (font (size 1.27 1.27)) hide) (effects (font (size 1.27 1.27)) hide)
) )
(pin "1" (uuid 56547516-be87-4c79-987f-2fc56540a1da)) (pin "1" (uuid 56547516-be87-4c79-987f-2fc56540a1da))
@ -1849,9 +1842,6 @@
(path "/ffeb9ebe-4380-4071-9467-9d7fac660fc5" (path "/ffeb9ebe-4380-4071-9467-9d7fac660fc5"
(reference "Q1") (unit 1) (value "D2061") (footprint "") (reference "Q1") (unit 1) (value "D2061") (footprint "")
) )
(path "/0d696145-2ec2-4bef-994b-9f1c8758cd4d"
(reference "R1") (unit 1) (value "161Ω") (footprint "")
)
(path "/44629472-077b-4fd8-ab99-7bd1e7b23c99" (path "/44629472-077b-4fd8-ab99-7bd1e7b23c99"
(reference "R4") (unit 1) (value "1kΩ") (footprint "") (reference "R4") (unit 1) (value "1kΩ") (footprint "")
) )

View file

@ -7,17 +7,20 @@
#define MODE_SETALARM 2 #define MODE_SETALARM 2
#define PIN_BUTTON 3 #define PIN_BUTTON 3
#define PIN_BUZZER_LOUD 8 #define PIN_BUZZER 5
#define PIN_BUZZER_QUIET 12
#define PIN_LED_DUTY A0
#define PIN_REG_CLOCK 7 #define PIN_REG_CLOCK 7
#define PIN_REG_DATA 5 #define PIN_REG_DATA 4
#define PIN_REG_LATCH 6 #define PIN_REG_LATCH 6
#define PIN_TOUCH_0 11
#define PIN_TOUCH_1 10
#define PIN_TOUCH_2 2
#define PIN_TOUCH_3 9
#define PIN_TOUCH_COM A1
CapacitiveSensor touch_0 = CapacitiveSensor(A1, 11); CapacitiveSensor touch_0 = CapacitiveSensor(PIN_TOUCH_COM, PIN_TOUCH_0);
CapacitiveSensor touch_1 = CapacitiveSensor(A1, 10); CapacitiveSensor touch_1 = CapacitiveSensor(PIN_TOUCH_COM, PIN_TOUCH_1);
CapacitiveSensor touch_2 = CapacitiveSensor(A1, 2); CapacitiveSensor touch_2 = CapacitiveSensor(PIN_TOUCH_COM, PIN_TOUCH_2);
CapacitiveSensor touch_3 = CapacitiveSensor(A1, 9); CapacitiveSensor touch_3 = CapacitiveSensor(PIN_TOUCH_COM, PIN_TOUCH_3);
// Matrix state // Matrix state
unsigned char matrix[8] = {0b10000001, 0, 0, 0, 0, 0, 0, 0b10000001}; unsigned char matrix[8] = {0b10000001, 0, 0, 0, 0, 0, 0, 0b10000001};
@ -44,6 +47,7 @@ unsigned long last_light_measure = 0;
unsigned long touch_time[4] = {0, 0, 0, 0}; unsigned long touch_time[4] = {0, 0, 0, 0};
unsigned long last_touch_measure = 0; unsigned long last_touch_measure = 0;
unsigned char touch_step = 0;
// Bytewise reverse // Bytewise reverse
unsigned char reverse(unsigned char b) { unsigned char reverse(unsigned char b) {
@ -111,8 +115,7 @@ void setup() {
pinMode(PIN_REG_DATA, OUTPUT); pinMode(PIN_REG_DATA, OUTPUT);
pinMode(PIN_REG_CLOCK, OUTPUT); pinMode(PIN_REG_CLOCK, OUTPUT);
pinMode(PIN_REG_LATCH, OUTPUT); pinMode(PIN_REG_LATCH, OUTPUT);
pinMode(PIN_BUZZER_QUIET, OUTPUT); pinMode(PIN_BUZZER, OUTPUT);
pinMode(PIN_BUZZER_LOUD, OUTPUT);
pinMode(PIN_BUTTON, INPUT_PULLUP); pinMode(PIN_BUTTON, INPUT_PULLUP);
pinMode(13, OUTPUT); pinMode(13, OUTPUT);
@ -133,23 +136,37 @@ void loop() {
#endif #endif
// Calibrate the thresholds according to your resistors // Calibrate the thresholds according to your resistors
if(millis() > last_touch_measure + 50) { if(millis() > last_touch_measure + 15) {
if(touch_0.capacitiveSensor(10) > 127 && millis() > touch_time[0] + 250) { switch(touch_step) {
case 0:
if(touch_0.capacitiveSensor(10) > 126 && millis() > touch_time[0] + 250) {
touch_time[0] = millis(); touch_time[0] = millis();
mode = (mode+1) % 3; mode = (mode+1) % 3;
stop_ringing();
} }
if(touch_1.capacitiveSensor(10) > 127 && millis() > touch_time[1] + 250) { break;
case 1:
if(touch_1.capacitiveSensor(10) > 126 && millis() > touch_time[1] + 250) {
touch_time[1] = millis(); touch_time[1] = millis();
number_selection = (number_selection+1) % 4; number_selection = (number_selection+1) % 4;
stop_ringing();
} }
if(touch_2.capacitiveSensor(10) > 32 && millis() > touch_time[2] + 200) { break;
case 2:
if(touch_2.capacitiveSensor(10) > 31 && millis() > touch_time[2] + 150) {
touch_time[2] = millis(); touch_time[2] = millis();
change_selected_number(1); change_selected_number(1);
stop_ringing();
} }
if(touch_3.capacitiveSensor(10) > 32 && millis() > touch_time[3] + 200) { break;
case 3:
if(touch_3.capacitiveSensor(10) > 31 && millis() > touch_time[3] + 150) {
touch_time[3] = millis(); touch_time[3] = millis();
change_selected_number(-1); change_selected_number(-1);
stop_ringing();
} }
}
touch_step = (touch_step + 1) % 4;
last_touch_measure = millis(); last_touch_measure = millis();
} }
@ -162,31 +179,15 @@ void loop() {
} }
if(alarm_ringing) { if(alarm_ringing) {
if(alarm_ring_start + 30000 > millis()) {
if(millis()%1000 < 100) { if(millis()%1000 < 100) {
matrix[7] = 0b11111111; matrix[7] = 0b11111111;
digitalWrite(PIN_BUZZER_LOUD, LOW); analogWrite(PIN_BUZZER, 1);
digitalWrite(PIN_BUZZER_QUIET, HIGH);
} else { } else {
matrix[7] = 0b10000001; matrix[7] = 0b10000001;
digitalWrite(PIN_BUZZER_LOUD, LOW); digitalWrite(PIN_BUZZER, LOW);
digitalWrite(PIN_BUZZER_QUIET, LOW);
}
} else {
if(millis()%1000 < 100) {
matrix[7] = 0b11111111;
digitalWrite(PIN_BUZZER_LOUD, HIGH);
digitalWrite(PIN_BUZZER_QUIET, LOW);
} else {
matrix[7] = 0b10000001;
digitalWrite(PIN_BUZZER_LOUD, LOW);
digitalWrite(PIN_BUZZER_QUIET, LOW);
}
} }
if(digitalRead(PIN_BUTTON) == LOW) { if(digitalRead(PIN_BUTTON) == LOW) {
digitalWrite(PIN_BUZZER_LOUD, LOW); stop_ringing();
digitalWrite(PIN_BUZZER_QUIET, LOW);
alarm_ringing = false;
} }
} }
@ -217,3 +218,9 @@ void change_time(unsigned long *t, signed int mul) {
} }
*t %= 86400000; *t %= 86400000;
} }
void stop_ringing() {
digitalWrite(PIN_BUZZER, LOW);
matrix[7] = 0b10000001;
alarm_ringing = false;
}