WIP: keep local changes before merging remote

This commit is contained in:
Filipriec
2025-11-13 14:42:47 +01:00
parent 915c573b27
commit 3c11e1dff8
9 changed files with 320 additions and 47 deletions

66
cvicenie_5/Led.cpp Normal file
View File

@@ -0,0 +1,66 @@
#include "Led.h"
// Constructor
Led::Led(PinName pin)
: led(pin)
{
led.period_ms(10);
led = 0;
};
// Destructor
Led::~Led()
{
};
void Led::set(bool s)
{
if(s)
led = 1;
else
led = 0;
};
void Led::setDuty(float duty)
{
led.write(duty);
};
float Led::getDuty()
{
return led.read(); // Return the current output duty-cycle setting
}
void Led::graduallyOn()
{
for(float i=0 ; i<=1; i=i+0.01)
{
this->setDuty(i);
ThisThread::sleep_for(20ms);
}
led = 0;
};
PwmOut* Led::getPwmOut()
{
return &led;
};
void Led::tickerHandler(void)
{
led = !led;
};
void Led::setBlinkPeriod(float period)
{
if(period<=0)
{
ticker.detach(); // turn off ticker
// set(false);
this->set(false); // turn off led
return;
}
// ticker.attach(callback(this, &Led::tickerHandler), period); // deprecated
auto float_interval = std::chrono::duration<float>(period);
ticker.attach(callback(this, &Led::tickerHandler), std::chrono::duration_cast<std::chrono::microseconds>(float_interval));
}