implemented basic handling of infrared

This commit is contained in:
hhaupt 2024-04-28 01:24:47 +02:00
parent dbe97dc94c
commit 39e424ed13
6 changed files with 94 additions and 76 deletions

View File

@ -1,13 +1,13 @@
#include <Adafruit_NeoPixel.h>
#include <Dezibot.h> #include <Dezibot.h>
#define GPIO_LED 48
Dezibot dezibot = Dezibot(); Dezibot dezibot = Dezibot();
void setup() { void setup() {
dezibot.begin(); dezibot.begin();
dezibot.infraredLight.front.turnOn();
dezibot.infraredLight.bottom.turnOn();
} }
void loop() { void loop() {
} }

View File

@ -4,79 +4,8 @@
#include "Dezibot.h" #include "Dezibot.h"
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_NeoPixel.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
// The pins for I2C are defined by the Wire-library.
// On an arduino UNO: A4(SDA), A5(SCL)
// On an arduino MEGA 2560: 20(SDA), 21(SCL)
// On an arduino LEONARDO: 2(SDA), 3(SCL), ...
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define GPIO_LED 48
void Dezibot::begin(void) { void Dezibot::begin(void) {
Adafruit_NeoPixel ledStrip = Adafruit_NeoPixel(3, GPIO_LED, NEO_GRB + NEO_KHZ800); infraredLight.begin();
Wire.begin(1, 2);
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println("SSD1306 allocation failed");
for (;;); // Don't proceed, loop forever
}
display.display();
vTaskDelay(2000);
display.clearDisplay();
vTaskDelay(2000);
// Draw a single pixel in white
display.drawPixel(10, 10, SSD1306_WHITE);
// Show the display buffer on the screen. You MUST call display() after
// drawing commands to make them visible on screen!
display.display();
vTaskDelay(2000);
Serial.begin(9600);
Serial.println("start");
vTaskDelay(1000);
while (1) {
/* Blink off (output low) */
ledStrip.setPixelColor(1, ledStrip.Color(100, 100, 100));
ledStrip.show(); // Aktualisiere die Farbe des Pixels
vTaskDelay(1000);
/* Blink on (output high) */
ledStrip.setPixelColor(1, ledStrip.Color(0, 0, 0));
ledStrip.show(); // Aktualisiere die Farbe des Pixels
vTaskDelay(1000);
struct timeval tv_now;
gettimeofday(&tv_now, NULL);
int64_t time_us = (int64_t) tv_now.tv_sec * 1000000L + (int64_t) tv_now.tv_usec;
Serial.println(time_us);
display.clearDisplay();
display.setTextSize(2); // Draw 2X-scale text
display.setTextColor(SSD1306_WHITE);
display.setCursor(10, 0);
display.println(F("scroll"));
display.display(); // Show initial text
vTaskDelay(1000);
}
} }

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 {
protected: protected:
@ -26,7 +27,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,22 @@
#include "InfraredLight.h"
InfraredLED::InfraredLED(uint8_t pin){
ledPin = pin;
};
void InfraredLED::begin(void){
pinMode(ledPin,OUTPUT);
};
void InfraredLED::turnOn(void){
InfraredLED::setState(true);
};
void InfraredLED::turnOff(void){
InfraredLED::setState(false);
};
void InfraredLED::setState(bool state){
digitalWrite(ledPin,state);
};

View File

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

View File

@ -0,0 +1,60 @@
/**
* @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>
enum IRLeds{
Bottom,
Front
};
class InfraredLED{
public:
InfraredLED(uint8_t pin);
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);
protected:
uint8_t ledPin;
};
class InfraredLight{
public:
InfraredLED bottom = InfraredLED(IRBottomPin);
InfraredLED front = InfraredLED(IRFrontPin);
void begin(void);
protected:
static const uint8_t IRFrontPin = 14;
static const uint8_t IRBottomPin = 13;
};
#endif //InfraredLight_h