Clock working, I2C communication to be proven
This commit is contained in:
55
Core/Src/clock.c
Normal file
55
Core/Src/clock.c
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* clock.c
|
||||
*
|
||||
* Created on: Mar 26, 2026
|
||||
* Author: ewars
|
||||
*/
|
||||
|
||||
|
||||
#include "clock.h"
|
||||
|
||||
// define LED marking 12:00 or 00:00
|
||||
#define LED_ZERO_OFFSET 10
|
||||
|
||||
|
||||
uint8_t clock_convert_hours(uint8_t hours){
|
||||
int8_t h = 0;
|
||||
uint8_t led = 0;
|
||||
|
||||
// input check
|
||||
if(hours < 24){
|
||||
|
||||
if(hours > 12){
|
||||
h = hours - 12;
|
||||
}
|
||||
else{
|
||||
h = hours;
|
||||
}
|
||||
|
||||
led = 2 * h + LED_ZERO_OFFSET;
|
||||
if(led > 23){
|
||||
led -= 24;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return led;
|
||||
|
||||
}
|
||||
|
||||
uint8_t clock_convert_min_sec(uint8_t min_sec){
|
||||
|
||||
float led = 0;
|
||||
|
||||
if(min_sec < 60){
|
||||
led = (float) min_sec/(60/24);
|
||||
|
||||
led += LED_ZERO_OFFSET;
|
||||
if(led > 23){
|
||||
led -= 24;
|
||||
}
|
||||
}
|
||||
|
||||
return (uint8_t) led;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user