LED clock
 All Files Functions Variables Macros Groups
Macros | Functions | Variables
main.c File Reference

show the time on a LED strip More...

Go to the source code of this file.

Macros

#define EXTERNAL_RTC   false
 use external RTC, else use internal RTC
 
#define TICKS_PER_SECOND   256
 the number of ticks in one second (32768 divisor greater than 256*LED_WS2812B_LEDS/60)
 
#define PHOTORESISTOR_ADC_CHANNEL   ADC_CHANNEL1
 ADC channel.
 
#define PHOTORESISTOR_PORT   GPIOA
 port on which the battery is connected
 
#define PHOTORESISTOR_PORT_RCC   RCC_GPIOA
 timer port peripheral clock
 
#define PHOTORESISTOR_PIN   GPIO1
 pin of the port on which the battery is connected
 
#define PHOTORESISTOR_MIN   2.7
 photo-resistor voltage for the minimum brightness
 
#define PHOTORESISTOR_MAX   1.7
 photo-resistor voltage for the maximum brightness
 
#define BRIGHTNESS_MIN   0.2
 minimum LED brightness
 
#define BRIGHTNESS_MAX   1.0
 maximum LED brightness
 
#define BRIGHTNESS_FACTOR   0.1
 the factor to change the brightness
 

Functions

int _write (int file, char *ptr, int len)
 default printf output
 
char * b2s (uint64_t binary, uint8_t rjust)
 get binary representation of a number More...
 
static void clock_clear (void)
 switch off all clock LEDs More...
 
static void clock_show_time (uint32_t time)
 show time on LED clock More...
 
static void clock_leds_set (void)
 set the LEDs More...
 
static void clock_set_time (uint32_t time)
 set the time on the LEDs More...
 
static void clock_animate_time (uint32_t time)
 incrementally set the time on the LEDs More...
 
static void clock_hours (void)
 show animation with fading hours mark on clock LEDs
 
static void process_command (char *str)
 process user command More...
 
int main (void)
 program entry point this is the firmware function started by the micro-controller
 
void adc1_2_isr (void)
 interrupt service routine called when ADC conversion completed
 
void rtc_isr (void)
 interrupt service routine called when tick passed on RTC
 

Variables

volatile bool button_flag = false
 flag set when board user button has been pressed/released
 
volatile bool photoresistor_flag = false
 flag set when ambient luminosity is measured
 
volatile bool rtc_internal_tick_flag = false
 flag set when internal RTC ticked
 
const uint32_t ticks_second = TICKS_PER_SECOND
 number of ticks in one second
 
const uint32_t ticks_minute = 60*TICKS_PER_SECOND
 number of ticks in one minute
 
const uint32_t ticks_hour = 60*60*TICKS_PER_SECOND
 number of ticks in one hour
 
const uint32_t ticks_midday = 12*60*60*TICKS_PER_SECOND
 number of ticks in one midday (12 hours)
 
uint8_t clock_leds [LED_WS2812B_LEDS *3] = {0}
 RGB values for the WS2812B clock LEDs.
 
char command [32] = {0}
 user input command
 
uint8_t command_i = 0
 user input command index
 
uint8_t gamma_correction_lut [256] = {0}
 gamma correction lookup table (common for all colors)
 
volatile uint16_t photoresistor_value = 0
 photo-resistor measurement of ambient luminosity
 
float clock_brightness = 1
 factor to dim LED of the clock, depending on the ambient luminosity
 

Detailed Description

show the time on a LED strip

Author
King Kévin kingk.nosp@m.evin.nosp@m.@cuvo.nosp@m.odoo.nosp@m..info
Date
2016

Definition in file main.c.

Function Documentation

char* b2s ( uint64_t  binary,
uint8_t  rjust 
)

get binary representation of a number

Parameters
[in]binarynumber to represent in binary
[in]rjustjustify representation with leading zeros
Returns
string with binary representation of the number

Definition at line 146 of file main.c.

static void clock_animate_time ( uint32_t  time)
static

incrementally set the time on the LEDs

this will have an animation where time is incremented until it reaches the provided time

Parameters
[in]timetime to set

Definition at line 282 of file main.c.

static void clock_clear ( void  )
static

switch off all clock LEDs

Note
LEDs need to be set separately

Definition at line 171 of file main.c.

static void clock_leds_set ( void  )
static

set the LEDs

set the LED colors on WS2812B LEDs

Note
WS2812B LED color values need to be transmitted separately

Definition at line 261 of file main.c.

static void clock_set_time ( uint32_t  time)
static

set the time on the LEDs

Parameters
[in]timetime to set

Definition at line 271 of file main.c.

static void clock_show_time ( uint32_t  time)
static

show time on LED clock

Parameters
[in]timein ticks to show

show hours and minutes progress as full arcs, show second position as marker. the brightness of the LED shows the progress of the unit. hours are blue, minutes green, seconds red

Note
LEDs need to be set separately

Definition at line 184 of file main.c.

static void process_command ( char *  str)
static

process user command

Parameters
[in]struser command string (\0 ended)

Definition at line 327 of file main.c.