Commits

Trammell Hudson  committed 20e0d09 Draft

Added switch and mode toggle

  • Participants
  • Parent commits 1f2cdb9

Comments (0)

Files changed (1)

File alphawatch.c

 #define RD	0xC7
 #define CLKSEL	0xD6
 
+#define BUTTON	0xD1
+
 static const char numbers[][16] = {
 	"",
 	"one",
 	_delay_ms(10);
 	out(RESET, 1);
 
-	uint8_t bright = 0;
+	// The push button is pull up and will be grounded when pressed
+	ddr(BUTTON, 0);
+	out(BUTTON, 1);
+
+	uint8_t bright = 3;
 
 	// We should be good to go
 	//lcd_write(0x20, 0x00); // normal operation
 	send_str(PSTR("alphawatch\r\n"));
 	char line[16];
 	uint8_t line_offset = 0;
+	uint8_t last_button = 0;
+	uint8_t mode = 1;
+	const uint8_t NUM_MODES = 2;
+	const uint8_t timeout = 1;
 
 	while (1)
 	{
+		if (!in(BUTTON))
+		{
+			if (last_button == 0xff || sec - last_button >= timeout)
+			{
+				last_button = sec;
+				mode = (mode + 1) % NUM_MODES;
+			}
+		} else {
+			last_button = 0xFF;
+		}
+
 		int c = usb_serial_getchar();
 		if (c != -1)
 		{
 			continue;
 		rate = 0;
 
-		const uint8_t mode = 1;
-
 		if (mode == 0)
 			draw_hms();
 		else