From 820ef77d478f2071499f80b234e49e3cbf35fd5a Mon Sep 17 00:00:00 2001 From: Derisis13 Date: Mon, 10 Apr 2023 17:57:20 +0200 Subject: [PATCH] feat: nyan cat animation (art by @bence98) --- main.c | 59 ++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 45 insertions(+), 14 deletions(-) diff --git a/main.c b/main.c index 38e7dfe..434a147 100644 --- a/main.c +++ b/main.c @@ -24,22 +24,53 @@ #include #include "PT6302.h" -int main () -{ +int main() { static const uint8_t digitstates[] = {0b00, 0b00, 0b00, 0b00, 0b00, 0b00, 0b00, 0b00, 0b00, 0b00, 0b00, 0b00}; - static const uint8_t custom_chars[8 * 5] = {0}; - static const uint8_t characters[] = + static const uint8_t custom_chars[8 * 5] = + { + // rainbow 1 @ address 0x00 + 0b0010010, 0b0100100, 0b0010010, 0b0100100, 0b0010010, + // rainbow 2 @ address 0x01 + 0b0100100, 0b0010010, 0b0100100, 0b0010010, 0b0100100, + // tail 1 @ address 0x02 + 0b0000000, 0b0001100, 0b0010000, 0b0111100, 0b0100110, + // tail 2 @ address 0x03 + 0b0000000, 0b0000000, 0b0001000, 0b0000000, 0b0000000, + // body @ address 0x04 + 0b0100110, 0b0100100, 0b0100110, 0b0100100, 0b0100110, + // body @ address 0x05 + 0b0100110, 0b0100100, 0b0100110, 0b0100100, 0b0100110, + // head 1 @ address 0x06 + 0b0001100, 0b0110010, 0b0001010, 0b0110010, 0b0001100, + // head 2 @ address 0x07 + 0b0011000, 0b1100100, 0b0010100, 0b1100100, 0b0011000, + }; + static const uint8_t ha5kfu[] = {0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x48, 0x41, 0x35, 0x4B, 0x46, 0x55, 0x20, 0x20, 0x20}; - PT6302_startup (); - set_ports (1, 1); - set_digits (DISPLAY_DIGITS); - set_duty (7); - set_ADRAM (0, digitstates, DISPLAY_DIGITS); - set_CGRAM (0, custom_chars, 8); - set_DCRAM (0, characters, DISPLAY_DIGITS); - set_display_mode (NORMAL_MODE); - while (1) - { + static const uint8_t blank[] = + {0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20}; + static const uint8_t even_frame[] = + {0x07, 0x05, 0x03, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00}; + static const uint8_t odd_frame[] = + {0x06, 0x04, 0x02, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01}; + PT6302_startup(); + set_ports(1, 1); + set_digits(DISPLAY_DIGITS); + set_duty(7); + set_ADRAM(0, digitstates, DISPLAY_DIGITS); + set_CGRAM(0, custom_chars, 8); + set_DCRAM(0, ha5kfu, DISPLAY_DIGITS); + set_display_mode(NORMAL_MODE); + _delay_ms(1000); + while (1) { + set_DCRAM(0, blank, DISPLAY_DIGITS); + for (int i = 0; i < DISPLAY_DIGITS; ++i) { + if (i % 2 == 0) + set_DCRAM(0, even_frame, i); + else + set_DCRAM(0, odd_frame, i); + _delay_ms(250); } + } }