include IR into release

This commit is contained in:
Prof.J.Wagner 2024-06-06 15:00:37 +02:00
commit be28c7b6f0
6 changed files with 162 additions and 2 deletions

View File

@ -0,0 +1,16 @@
#include <Dezibot.h>
Dezibot dezibot = Dezibot();
void setup() {
dezibot.begin();
//dezibot.infraredLight.front.turnOn();
//dezibot.infraredLight.bottom.turnOn();
}
void loop() {
dezibot.infraredLight.bottom.turnOn();
delay(1000);
dezibot.infraredLight.bottom.turnOff();
delay(1000);
}

View File

@ -11,12 +11,17 @@
#include "Dezibot.h" #include "Dezibot.h"
#include <SPI.h>
#include <Wire.h>
Dezibot::Dezibot():multiColorLight(),motionDetection(){ Dezibot::Dezibot():multiColorLight(),motionDetection(){
};
#define GPIO_LED 48
void Dezibot::begin(void) { void Dezibot::begin(void) {
infraredLight.begin();
motion.begin(); motion.begin();
multiColorLight.begin(); multiColorLight.begin();
lightDetection.begin(); lightDetection.begin();

View File

@ -16,6 +16,7 @@
#include "colorDetection/ColorDetection.h" #include "colorDetection/ColorDetection.h"
#include "multiColorLight/MultiColorLight.h" #include "multiColorLight/MultiColorLight.h"
#include "motionDetection/MotionDetection.h" #include "motionDetection/MotionDetection.h"
#include "infraredLight/InfraredLight.h"
class Dezibot { class Dezibot {
@ -28,7 +29,7 @@ public:
ColorDetection colorDetection; ColorDetection colorDetection;
MultiColorLight multiColorLight; MultiColorLight multiColorLight;
MotionDetection motionDetection; MotionDetection motionDetection;
InfraredLight infraredLight;
void begin(void); void begin(void);
/* /*
Display display Display display

View File

@ -0,0 +1,59 @@
#include "InfraredLight.h"
#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){
//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){
InfraredLED::setState(true);
};
void InfraredLED::turnOff(void){
InfraredLED::setState(false);
};
void InfraredLED::setState(bool 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);
};

View File

@ -0,0 +1,6 @@
#include "InfraredLight.h"
void InfraredLight::begin(void){
bottom.begin();
front.begin();
}

View File

@ -0,0 +1,73 @@
/**
* @file InfraredLight.h
* @author Hans Haupt (hans.haupt@dezibot.de)
* @brief Provides basic controls for the infrared LEDs of the robot.
* @version 0.1
* @date 2024-04-27
*
* @copyright Copyright (c) 2024
*
*/
#ifndef InfraredLight_h
#define InfraredLight_h
#include <stdint.h>
#include <Arduino.h>
#include "driver/ledc.h"
enum IRLeds{
Bottom,
Front
};
class InfraredLED{
public:
InfraredLED(uint8_t pin, ledc_timer_t timer, ledc_channel_t channel);
void begin(void);
/**
* @brief enables selected LED
*
* @param led
*/
void turnOn(void);
/**
* @brief disables selected LED
*
* @param led
*/
void turnOff(void);
/**
* @brief changes state of selected LED depending on the state
*
* @param led which led will be affected
* @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:
//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:
static const uint8_t IRFrontPin = 14;
static const uint8_t IRBottomPin = 13;
};
#endif //InfraredLight_h