mirror of
https://gitlab.dit.htwk-leipzig.de/phillip.kuehne/dezibot.git
synced 2025-05-20 03:21:46 +02:00
added the possibility of sending a specific frequency via IR
This commit is contained in:
parent
39e424ed13
commit
1596b3883c
@ -1,13 +0,0 @@
|
||||
#include <Dezibot.h>
|
||||
|
||||
Dezibot dezibot = Dezibot();
|
||||
|
||||
void setup() {
|
||||
dezibot.begin();
|
||||
dezibot.infraredLight.front.turnOn();
|
||||
dezibot.infraredLight.bottom.turnOn();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
}
|
@ -1,12 +1,36 @@
|
||||
#include "InfraredLight.h"
|
||||
|
||||
|
||||
InfraredLED::InfraredLED(uint8_t pin){
|
||||
ledPin = pin;
|
||||
#define pwmSpeedMode LEDC_LOW_SPEED_MODE
|
||||
#define fooPin 13
|
||||
#define footimer LEDC_TIMER_0
|
||||
#define foochannel LEDC_CHANNEL_0
|
||||
InfraredLED::InfraredLED(uint8_t pin,ledc_timer_t timer, ledc_channel_t channel){
|
||||
this->ledPin = pin;
|
||||
this->timer = timer;
|
||||
this->channel = channel;
|
||||
};
|
||||
|
||||
void InfraredLED::begin(void){
|
||||
pinMode(ledPin,OUTPUT);
|
||||
//we want to change frequency instead of
|
||||
pwmTimer = ledc_timer_config_t{
|
||||
.speed_mode = pwmSpeedMode,
|
||||
.duty_resolution = LEDC_TIMER_10_BIT,
|
||||
.timer_num = this->timer,
|
||||
.freq_hz = 1,
|
||||
.clk_cfg = LEDC_AUTO_CLK
|
||||
};
|
||||
ledc_timer_config(&pwmTimer);
|
||||
|
||||
pwmChannel = ledc_channel_config_t{
|
||||
.gpio_num = this->ledPin,
|
||||
.speed_mode =pwmSpeedMode,
|
||||
.channel = this->channel,
|
||||
.intr_type = LEDC_INTR_DISABLE,
|
||||
.timer_sel = this->timer,
|
||||
.duty = 0,
|
||||
.hpoint = 0
|
||||
};
|
||||
ledc_channel_config(&pwmChannel);
|
||||
};
|
||||
|
||||
void InfraredLED::turnOn(void){
|
||||
@ -18,5 +42,18 @@ void InfraredLED::turnOff(void){
|
||||
};
|
||||
|
||||
void InfraredLED::setState(bool state){
|
||||
digitalWrite(ledPin,state);
|
||||
ledc_set_freq(pwmSpeedMode,timer,1);
|
||||
if (state) {
|
||||
ledc_set_duty(pwmSpeedMode,channel,1023);
|
||||
} else {
|
||||
ledc_set_duty(pwmSpeedMode,channel,0);
|
||||
}
|
||||
ledc_update_duty(pwmSpeedMode,channel);
|
||||
|
||||
};
|
||||
|
||||
void InfraredLED::sendFrequency(uint16_t frequency){
|
||||
ledc_set_freq(pwmSpeedMode,timer,frequency);
|
||||
ledc_set_duty(pwmSpeedMode,channel,512);
|
||||
ledc_update_duty(pwmSpeedMode,channel);
|
||||
};
|
@ -12,6 +12,7 @@
|
||||
#define InfraredLight_h
|
||||
#include <stdint.h>
|
||||
#include <Arduino.h>
|
||||
#include "driver/ledc.h"
|
||||
|
||||
enum IRLeds{
|
||||
Bottom,
|
||||
@ -20,7 +21,7 @@ enum IRLeds{
|
||||
|
||||
class InfraredLED{
|
||||
public:
|
||||
InfraredLED(uint8_t pin);
|
||||
InfraredLED(uint8_t pin, ledc_timer_t timer, ledc_channel_t channel);
|
||||
void begin(void);
|
||||
/**
|
||||
* @brief enables selected LED
|
||||
@ -41,14 +42,26 @@ class InfraredLED{
|
||||
* @param state true if led should be turned on, else false
|
||||
*/
|
||||
void setState(bool state);
|
||||
/**
|
||||
* @brief starts flashing the IRLed with a specific frequency
|
||||
* Won't stop automatically, must be stopped by calling any other IR-Method
|
||||
*
|
||||
* @param frequency
|
||||
*/
|
||||
void sendFrequency(uint16_t frequency);
|
||||
protected:
|
||||
uint8_t ledPin;
|
||||
ledc_timer_t timer;
|
||||
ledc_channel_t channel;
|
||||
ledc_timer_config_t pwmTimer;
|
||||
ledc_channel_config_t pwmChannel;
|
||||
};
|
||||
|
||||
class InfraredLight{
|
||||
public:
|
||||
InfraredLED bottom = InfraredLED(IRBottomPin);
|
||||
InfraredLED front = InfraredLED(IRFrontPin);
|
||||
//Do something for correct resource sharing
|
||||
InfraredLED bottom = InfraredLED(IRBottomPin,LEDC_TIMER_0,LEDC_CHANNEL_0);
|
||||
InfraredLED front = InfraredLED(IRFrontPin,LEDC_TIMER_1,LEDC_CHANNEL_1);
|
||||
void begin(void);
|
||||
|
||||
protected:
|
||||
|
Loading…
x
Reference in New Issue
Block a user