Initial commit

This commit is contained in:
Pascal Engélibert 2022-09-01 15:53:01 +02:00
commit fe99a96406
Signed by: tuxmain
GPG key ID: 3504BC6D362F7DCA
7 changed files with 2176 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/alarmclock/alarmclock-backups

30
README.md Normal file
View file

@ -0,0 +1,30 @@
# Alarm clock
Arduino alarm clock with binary matrix LED display and IR remote control.
## Features
* 8×8 LED display using two 74HC595N
* hour-minute-second binary display
* buzzer alarm
* IR remote control for settings and stopping alarm
* big pushbutton for stopping alarm
* light sensor for dimming display
## TODO
* supercapacitor & low-voltage detection
* casing
* multiple alarms
* better LED dimming (maybe use PWM on 74HC's OE)
* date (at least weekday)
* connection with online timetable?
* progressive alarm ringing
## License
GNU AGPL v3, CopyLeft 2022 Pascal Engélibert
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, version 3 of the License.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.

View file

@ -0,0 +1,2 @@
(kicad_pcb (version 20211014) (generator pcbnew)
)

View file

@ -0,0 +1,75 @@
{
"board": {
"active_layer": 0,
"active_layer_preset": "",
"auto_track_width": true,
"hidden_nets": [],
"high_contrast_mode": 0,
"net_color_mode": 1,
"opacity": {
"pads": 1.0,
"tracks": 1.0,
"vias": 1.0,
"zones": 0.6
},
"ratsnest_display_mode": 0,
"selection_filter": {
"dimensions": true,
"footprints": true,
"graphics": true,
"keepouts": true,
"lockedItems": true,
"otherItems": true,
"pads": true,
"text": true,
"tracks": true,
"vias": true,
"zones": true
},
"visible_items": [
0,
1,
2,
3,
4,
5,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
32,
33,
34,
35,
36
],
"visible_layers": "fffffff_ffffffff",
"zone_display_mode": 0
},
"meta": {
"filename": "alarmclock.kicad_prl",
"version": 3
},
"project": {
"files": []
}
}

View file

@ -0,0 +1,326 @@
{
"board": {
"design_settings": {
"defaults": {
"board_outline_line_width": 0.1,
"copper_line_width": 0.2,
"copper_text_size_h": 1.5,
"copper_text_size_v": 1.5,
"copper_text_thickness": 0.3,
"other_line_width": 0.15,
"silk_line_width": 0.15,
"silk_text_size_h": 1.0,
"silk_text_size_v": 1.0,
"silk_text_thickness": 0.15
},
"diff_pair_dimensions": [],
"drc_exclusions": [],
"rules": {
"min_copper_edge_clearance": 0.0,
"solder_mask_clearance": 0.0,
"solder_mask_min_width": 0.0
},
"track_widths": [],
"via_dimensions": []
},
"layer_presets": []
},
"boards": [],
"cvpcb": {
"equivalence_files": []
},
"erc": {
"erc_exclusions": [],
"meta": {
"version": 0
},
"pin_map": [
[
0,
0,
0,
0,
0,
0,
1,
0,
0,
0,
0,
2
],
[
0,
2,
0,
1,
0,
0,
1,
0,
2,
2,
2,
2
],
[
0,
0,
0,
0,
0,
0,
1,
0,
1,
0,
1,
2
],
[
0,
1,
0,
0,
0,
0,
1,
1,
2,
1,
1,
2
],
[
0,
0,
0,
0,
0,
0,
1,
0,
0,
0,
0,
2
],
[
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
2
],
[
1,
1,
1,
1,
1,
0,
1,
1,
1,
1,
1,
2
],
[
0,
0,
0,
1,
0,
0,
1,
0,
0,
0,
0,
2
],
[
0,
2,
1,
2,
0,
0,
1,
0,
2,
2,
2,
2
],
[
0,
2,
0,
1,
0,
0,
1,
0,
2,
0,
0,
2
],
[
0,
2,
1,
1,
0,
0,
1,
0,
2,
0,
0,
2
],
[
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2
]
],
"rule_severities": {
"bus_definition_conflict": "error",
"bus_entry_needed": "error",
"bus_label_syntax": "error",
"bus_to_bus_conflict": "error",
"bus_to_net_conflict": "error",
"different_unit_footprint": "error",
"different_unit_net": "error",
"duplicate_reference": "error",
"duplicate_sheet_names": "error",
"extra_units": "error",
"global_label_dangling": "warning",
"hier_label_mismatch": "error",
"label_dangling": "error",
"lib_symbol_issues": "warning",
"multiple_net_names": "warning",
"net_not_bus_member": "warning",
"no_connect_connected": "warning",
"no_connect_dangling": "warning",
"pin_not_connected": "error",
"pin_not_driven": "error",
"pin_to_pin": "warning",
"power_pin_not_driven": "error",
"similar_labels": "warning",
"unannotated": "error",
"unit_value_mismatch": "error",
"unresolved_variable": "error",
"wire_dangling": "error"
}
},
"libraries": {
"pinned_footprint_libs": [],
"pinned_symbol_libs": []
},
"meta": {
"filename": "alarmclock.kicad_pro",
"version": 1
},
"net_settings": {
"classes": [
{
"bus_width": 12.0,
"clearance": 0.2,
"diff_pair_gap": 0.25,
"diff_pair_via_gap": 0.25,
"diff_pair_width": 0.2,
"line_style": 0,
"microvia_diameter": 0.3,
"microvia_drill": 0.1,
"name": "Default",
"pcb_color": "rgba(0, 0, 0, 0.000)",
"schematic_color": "rgba(0, 0, 0, 0.000)",
"track_width": 0.25,
"via_diameter": 0.8,
"via_drill": 0.4,
"wire_width": 6.0
}
],
"meta": {
"version": 2
},
"net_colors": null
},
"pcbnew": {
"last_paths": {
"gencad": "",
"idf": "",
"netlist": "",
"specctra_dsn": "",
"step": "",
"vrml": ""
},
"page_layout_descr_file": ""
},
"schematic": {
"annotate_start_num": 0,
"drawing": {
"default_line_thickness": 6.0,
"default_text_size": 50.0,
"field_names": [],
"intersheets_ref_own_page": false,
"intersheets_ref_prefix": "",
"intersheets_ref_short": false,
"intersheets_ref_show": false,
"intersheets_ref_suffix": "",
"junction_size_choice": 3,
"label_size_ratio": 0.375,
"pin_symbol_size": 25.0,
"text_offset_ratio": 0.15
},
"legacy_lib_dir": "",
"legacy_lib_list": [],
"meta": {
"version": 1
},
"net_format_name": "",
"ngspice": {
"fix_include_paths": true,
"fix_passive_vals": false,
"meta": {
"version": 0
},
"model_mode": 0,
"workbook_filename": ""
},
"page_layout_descr_file": "",
"plot_directory": "",
"spice_adjust_passive_values": false,
"spice_external_command": "spice \"%I\"",
"subpart_first_id": 65,
"subpart_id_separator": 0
},
"sheets": [
[
"31f0e89d-6653-4742-b71a-b6b31bd0b8fd",
""
]
],
"text_variables": {}
}

File diff suppressed because it is too large Load diff

233
matrixclock/matrixclock.ino Normal file
View file

@ -0,0 +1,233 @@
#include <IRremote.h>
#define SERIAL_DEBUG 0
// Remote controls
#define RC6_CHM 0xFFA25D// CHANNEL -
#define RC6_CH 0xFF629D// CHANNEL
#define RC6_CHP 0xFFE21D// CHANNEL +
#define RC6_PREV 0xFF22DD// |<< PREVIOUS
#define RC6_NEXT 0xFF02FD// >>| NEXT
#define RC6_PLAY 0xFFC23D// PLAY/PAUSE
#define RC6_VM 0xFFE01F// VOLUME -
#define RC6_VP 0xFFA857// VOLUME +
#define RC6_EQ 0xFF906F// EQ
#define RC6_0 0xFF6897// 0
#define RC6_100 0xFF9867// 100+
#define RC6_200 0xFFB04F// 200+
#define RC6_1 0xFF30CF// 1
#define RC6_2 0xFF18E7// 2
#define RC6_3 0xFF7A85// 3
#define RC6_4 0xFF10EF// 4
#define RC6_5 0xFF38C7// 5
#define RC6_6 0xFF5AA5// 6
#define RC6_7 0xFF42BD// 7
#define RC6_8 0xFF4AB5// 8
#define RC6_9 0xFF52AD// 9
#define AMP2540_VCDAUX 0x8FDBCE66
#define AMP2540_TUNERCD 0xC375A98B
#define AMP2540_DVD 0xCC7372A6
#define AMP2540_TAPE 0xE917A076
#define AMP2540_SEARCH 0xE82D76B6
#define AMP2540_RESET 0x04D1A486
#define AMP2540_VM 0xAB95D276
#define AMP2540_VP 0x0217C346
#define MODE_NORMAL 0
#define MODE_SETTIME 1
#define MODE_SETALARM 2
#define PIN_BUTTON 3
#define PIN_BUZZER 8
#define PIN_IR 10
#define PIN_LED_DUTY A0
#define PIN_REG_CLOCK 7
#define PIN_REG_DATA 5
#define PIN_REG_LATCH 6
IRrecv irrecv(PIN_IR);
decode_results ircode;
unsigned long last_ir = 0;
// Matrix state
unsigned char matrix[8] = {0b10000001, 0, 0, 0, 0, 0, 0, 0b10000001};
unsigned char matrix_row_on = 0;
// Interface mode
unsigned char mode = MODE_NORMAL;
// Selected number (0..4: None, Hour, Minute, Second)
unsigned char number_selection = 0;
// Time added to internal clock, to fit real time
unsigned long time_offset = 0;
unsigned char alarm = false;
unsigned long alarm_time = 0;
// Is alarm ringing
unsigned char alarm_ringing = false;
unsigned int led_duty;
unsigned int led_duty_step = 3;
// Bytewise reverse
unsigned char reverse(unsigned char b) {
b = (b & 0xF0) >> 4 | (b & 0x0F) << 4;
b = (b & 0xCC) >> 2 | (b & 0x33) << 2;
b = (b & 0xAA) >> 1 | (b & 0x55) << 1;
return b;
}
unsigned char fix_pixels(unsigned char b) {
return (b << 1) | (b >> 7);
}
void shift_matrix() {
if(led_duty_step == 0) {
digitalWrite(PIN_REG_LATCH, LOW);
shiftOut(PIN_REG_DATA, PIN_REG_CLOCK, MSBFIRST, ~(1 << matrix_row_on));
shiftOut(PIN_REG_DATA, PIN_REG_CLOCK, MSBFIRST, fix_pixels(matrix[(matrix_row_on+7)%8]));
digitalWrite(PIN_REG_LATCH, HIGH);
matrix_row_on = (matrix_row_on + 1) % 8;
} else if(led_duty_step == 1) {
digitalWrite(PIN_REG_LATCH, LOW);
shiftOut(PIN_REG_DATA, PIN_REG_CLOCK, MSBFIRST, 255);
shiftOut(PIN_REG_DATA, PIN_REG_CLOCK, MSBFIRST, 0);
digitalWrite(PIN_REG_LATCH, HIGH);
}
led_duty_step ++;
}
void draw_time(unsigned long t) {
unsigned char seconds = t/1000%60;
unsigned char minutes = t/60000%60;
unsigned char hours = t/3600000%24;
matrix[1] = reverse(seconds) >> 1;
matrix[2] = matrix[1];
matrix[3] = reverse(minutes) >> 1;
matrix[4] = matrix[3];
matrix[5] = reverse(hours) >> 1;
matrix[6] = matrix[5];
}
void draw_mode() {
switch(mode) {
case MODE_NORMAL: matrix[0] = 0b10000001; break;
case MODE_SETTIME: matrix[0] = 0b10011001; break;
case MODE_SETALARM: matrix[0] = 0b10111101; break;
}
if(alarm) matrix[0] |= 0b01000010;
}
void draw_number_selection() {
switch(number_selection) {
case 1: matrix[1] |= 0b10000001; break;
case 2: matrix[3] |= 0b10000001; break;
case 3: matrix[5] |= 0b10000001; break;
}
}
const unsigned char HEX_ALPHA[16] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
void send_hex(unsigned long val) {
Serial.write(HEX_ALPHA[(val >> 28) & 0xf]);
Serial.write(HEX_ALPHA[(val >> 24) & 0xf]);
Serial.write(HEX_ALPHA[(val >> 20) & 0xf]);
Serial.write(HEX_ALPHA[(val >> 16) & 0xf]);
Serial.write(HEX_ALPHA[(val >> 12) & 0xf]);
Serial.write(HEX_ALPHA[(val >> 8) & 0xf]);
Serial.write(HEX_ALPHA[(val >> 4) & 0xf]);
Serial.write(HEX_ALPHA[val & 0xf]);
Serial.write('\n');
}
void setup() {
pinMode(PIN_REG_DATA, OUTPUT);
pinMode(PIN_REG_CLOCK, OUTPUT);
pinMode(PIN_REG_LATCH, OUTPUT);
pinMode(PIN_BUZZER, OUTPUT);
pinMode(PIN_BUTTON, INPUT_PULLUP);
pinMode(PIN_LED_DUTY, INPUT);
irrecv.enableIRIn();
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
#if SERIAL_DEBUG
Serial.begin(9600);
#endif
}
void loop() {
if(led_duty_step > led_duty) {
led_duty_step = 0;
led_duty = (1023-analogRead(PIN_LED_DUTY)) / 128;
}
if(irrecv.decode(&ircode)) {
#if SERIAL_DEBUG
send_hex(ircode.value);
#endif
unsigned long val = ircode.value;
if(val == last_ir) {
alarm_ringing = false;
switch(val) {
case AMP2540_VCDAUX: mode = (mode+1) % 3; break;
case AMP2540_VP: change_selected_number(1); break;
case AMP2540_VM: change_selected_number(-1); break;
case AMP2540_SEARCH: number_selection = (number_selection+1) % 4; break;
case AMP2540_TUNERCD: alarm = !alarm; break;
}
last_ir = 0;
} else {
last_ir = val;
}
irrecv.resume();
}
if(alarm && !alarm_ringing) {
unsigned long t = ((millis() + time_offset) / 1000) % 86400;
if(alarm_time / 1000 == t) {
alarm_ringing = true;
}
}
if(alarm_ringing) {
if(millis()%1000 < 100) {
matrix[7] = 0b11111111;
digitalWrite(PIN_BUZZER, HIGH);
} else {
matrix[7] = 0b10000001;
digitalWrite(PIN_BUZZER, LOW);
}
if(digitalRead(PIN_BUTTON) == LOW) {
digitalWrite(PIN_BUZZER, LOW);
alarm_ringing = false;
}
}
draw_mode();
if(mode == MODE_SETALARM)
draw_time(alarm_time);
else
draw_time(millis() + time_offset);
draw_number_selection();
shift_matrix();
}
void change_selected_number(signed int nb) {
switch(mode) {
case MODE_SETTIME: change_time(&time_offset, nb); break;
case MODE_SETALARM: change_time(&alarm_time, nb); break;
}
}
void change_time(unsigned long *t, signed int mul) {
switch(number_selection) {
case 1: *t += mul * 1000; break;
case 2: *t += mul * 60000; break;
case 3: *t += mul * 3600000; break;
}
*t %= 86400000;
}