LED clock
 All Files Functions Variables Macros Groups Pages
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 TICKS_PER_SECOND   256
 
#define BATTERY_ADC_CHANNEL   ADC_CHANNEL1
 
#define BATTERY_PORT   GPIOA
 
#define BATTERY_PORT_RCC   RCC_GPIOA
 
#define BATTERY_PIN   GPIO1
 
#define PHOTORESISTOR_ADC_CHANNEL   ADC_CHANNEL0
 
#define PHOTORESISTOR_PORT   GPIOA
 
#define PHOTORESISTOR_PORT_RCC   RCC_GPIOA
 
#define PHOTORESISTOR_PIN   GPIO0
 
#define PHOTORESISTOR_MIN   2.7
 
#define PHOTORESISTOR_MAX   1.7
 
#define BRIGHTNESS_MIN   0.2
 
#define BRIGHTNESS_MAX   1.0
 
#define BRIGHTNESS_FACTOR   0.1
 

Functions

int _write (int file, char *ptr, int len)
 default printf output
 
char * b2s (uint32_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 rtc_isr (void)
 interrupt service routine called when tick passed on RTC
 
void adc1_2_isr (void)
 interrupt service routine called when ADC conversion completed
 

Variables

volatile bool button_flag = false
 
volatile bool time_flag = false
 
volatile bool photoresistor_flag = false
 
const uint32_t ticks_second = TICKS_PER_SECOND
 
const uint32_t ticks_minute = 60*TICKS_PER_SECOND
 
const uint32_t ticks_hour = 60*60*TICKS_PER_SECOND
 
const uint32_t ticks_midday = 12*60*60*TICKS_PER_SECOND
 
uint8_t clock_leds [WS2812B_LEDS *3] = {0}
 
char command [32] = {0}
 
uint8_t command_i = 0
 
uint8_t gamma_correction_lut [256] = {0}
 
volatile uint16_t photoresistor_value = 0
 
float clock_brightness = 1
 

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.

Macro Definition Documentation

#define BRIGHTNESS_FACTOR   0.1

the factor to change the brightness

Definition at line 111 of file main.c.

#define BRIGHTNESS_MAX   1.0

maximum LED brightness

Definition at line 109 of file main.c.

#define BRIGHTNESS_MIN   0.2

minimum LED brightness

Definition at line 107 of file main.c.

#define PHOTORESISTOR_MAX   1.7

photo-resistor voltage for the maximum brightness

Definition at line 103 of file main.c.

#define PHOTORESISTOR_MIN   2.7

photo-resistor voltage for the minimum brightness

Definition at line 101 of file main.c.

Function Documentation

char* b2s ( uint32_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 132 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 268 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 157 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 247 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 257 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 170 of file main.c.

static void process_command ( char *  str)
static

process user command

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

Definition at line 313 of file main.c.

Variable Documentation

float clock_brightness = 1

factor to dim LED of the clock, depending on the ambient luminosity

Definition at line 105 of file main.c.

uint8_t clock_leds[WS2812B_LEDS *3] = {0}

RGB values for the WS2812b clock LEDs

Definition at line 91 of file main.c.

char command[32] = {0}

user input command

Definition at line 93 of file main.c.

uint8_t command_i = 0

user input command index

Definition at line 95 of file main.c.

uint8_t gamma_correction_lut[256] = {0}

gamma correction lookup table (common for all colors)

Definition at line 97 of file main.c.

volatile uint16_t photoresistor_value = 0

photo-resistor measurement of ambient luminosity

Definition at line 99 of file main.c.