summaryrefslogtreecommitdiffstats
path: root/Smol Watch Project/My Project/main.c
blob: 27f773179f0abd12bc38abf2c5730e5c0a6374c9 (plain)
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
#include <atmel_start.h>
#include "watch-library/watch.h"

int main(void)
{
	atmel_start_init();
	
	Watch watch;
	struct calendar_date_time date_time;
	date_time.date.year = 2021;
	date_time.date.month = 4;
	date_time.date.day = 25;
	date_time.time.hour = 4;
	date_time.time.min = 0;
	date_time.time.sec = 0;

	watch_init(&watch);
	watch_enable_led();
	watch_enable_date_time();
	watch_set_date_time(date_time);
	watch_enable_digital_output(A0);
	gpio_set_pin_level(A0, true);
	watch_enable_i2c();
	
	uint8_t chipID = 0;
	uint8_t ChipIdRegister = 0xD0;
	watch_i2c_send(0x77, &ChipIdRegister, 1);
	watch_i2c_receive(0x77, &chipID, 1);
	if (chipID == 0x60) {
		watch_set_led_green();
	}

	uint8_t last = date_time.time.sec;
	
	while (1) {
		watch_get_date_time(&date_time);
		if (date_time.time.sec != last) {
			last = date_time.time.sec;
			if (last % 2 == 0) {
				watch_set_led_red();
			} else {
				watch_set_led_green();
			}
		}
	}
	
	return 0;
}