From 6aaefc300fe7d9648b4150ab0fe17d6a883c854b Mon Sep 17 00:00:00 2001 From: Derisis13 Date: Mon, 7 Mar 2022 17:17:16 +0100 Subject: [PATCH] * Feature: `set_digits()` for setting VFD digits --- PT6302.c | 13 ++++++++++++- PT6302.h | 7 +++++++ main.c | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/PT6302.c b/PT6302.c index 224a583..4551d9e 100644 --- a/PT6302.c +++ b/PT6302.c @@ -58,6 +58,17 @@ void set_duty (uint8_t brightness) { brightness = 7; } - uint8_t command = 0x50 | brightness; + const uint8_t command = 0x50 | brightness; + transmit_bytes (&command, 1); +} + +void set_digits (uint8_t digit_count) +{ + if (digit_count >= 16) + digit_count = 8; //we'll subtract 8 later from this number + if (digit_count < 9) + digit_count = 9; + digit_count -= 8; + const uint8_t command = 0x60 | digit_count; transmit_bytes (&command, 1); } diff --git a/PT6302.h b/PT6302.h index bf6599f..3a06842 100644 --- a/PT6302.h +++ b/PT6302.h @@ -37,6 +37,13 @@ void transmit_bytes (const uint8_t *payload, uint8_t size); * --------------------------------------------------------- */ void set_ports (uint8_t gp1, uint8_t gp2); +/* --------------------------------------------------------------------------------------- + * Sets the number of digit_count the VFD has + * digit_count below 9 are interpreted as 9 and digit_count above 16 are interpreted as 16 + * Handles the entire communication + * --------------------------------------------------------------------------------------- */ +void set_digits(uint8_t digit_count); + /* ----------------------------------------------------------- * Sets duty cycle of controlled VFD * Brightness between 0 and 7 are accepted, any higher means 7 diff --git a/main.c b/main.c index d2e6f0e..578c4aa 100644 --- a/main.c +++ b/main.c @@ -12,6 +12,7 @@ int main () { PT6302_startup (); set_ports (1, 1); + set_digits (12); set_duty (7); while (1) {