added example sketches

This commit is contained in:
Hans Haupt
2024-06-14 08:27:34 +02:00
parent dbec7278f3
commit a0e6661b16
18 changed files with 186 additions and 65 deletions

View File

@ -0,0 +1,19 @@
#include "Dezibot.h"
Dezibot dezibot = Dezibot();
void setup() {
// put your setup code here, to run once:
dezibot.begin();
}
void loop() {
// put your main code here, to run repeatedly:
dezibot.multiColorLight.setLed(TOP, RED);
delay(2000);
dezibot.multiColorLight.setLed(TOP, YELLOW);
delay(2000);
dezibot.multiColorLight.setLed(TOP, GREEN);
delay(2000);
dezibot.multiColorLight.setLed(TOP, YELLOW);
delay(2000);
}

View File

@ -0,0 +1,29 @@
#include "Dezibot.h"
Dezibot dezibot = Dezibot();
void setup() {
// put your setup code here, to run once:
dezibot.begin();
}
void loop() {
// put your main code here, to run repeatedly:
dezibot.multiColorLight.setLed(TOP, RED);
delay(2000);
dezibot.multiColorLight.setLed(TOP, YELLOW);
delay(2000);
dezibot.multiColorLight.setLed(TOP, GREEN);
delay(2000);
dezibot.multiColorLight.turnOffLed();
delay(1000);
for(int i=0; i<3; i++){
dezibot.multiColorLight.setLed(TOP, GREEN);
delay(500);
dezibot.multiColorLight.turnOffLed();
delay(500);
}
dezibot.multiColorLight.setLed(TOP, YELLOW);
delay(2000);
}

View File

@ -0,0 +1,34 @@
#include "Dezibot.h"
Dezibot dezibot = Dezibot();
void setup() {
// put your setup code here, to run once:
dezibot.begin();
}
void loop() {
// put your main code here, to run repeatedly:
if(dezibot.motion.detection.isShaken()){
dezibot.multiColorLight.setLed(TOP, YELLOW);
delay(2000);
dezibot.multiColorLight.setLed(TOP, GREEN);
delay(2000);
dezibot.multiColorLight.turnOffLed();
delay(1000);
for(int i=0; i<3; i++){
dezibot.multiColorLight.setLed(TOP, GREEN);
delay(500);
dezibot.multiColorLight.turnOffLed();
delay(500);
}
dezibot.multiColorLight.setLed(TOP, YELLOW);
delay(2000);
}
else{
dezibot.multiColorLight.setLed(TOP, RED);
}
}

View File

@ -0,0 +1,8 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
"version": "0.2.0",
"configurations": [
]
}

View File

@ -6,12 +6,43 @@ const int centeredThreshold = 50 ;
void setup() {
// put your setup code here, to run once:
dezibot.begin();
//Serial.begin(115200);
dezibot.infraredLight.bottom.turnOn();
dezibot.infraredLight.front.turnOn();
Serial.begin(115200);
}
void loop() {
int32_t leftValue = (int32_t)dezibot.lightDetection.getAverageValue(IR_LEFT, 20, 1);
int32_t rightValue = (int32_t)dezibot.lightDetection.getAverageValue(IR_RIGHT, 20, 1);
switch(dezibot.lightDetection.getBrightest(IR)){
case IR_FRONT:
//correct Stearing to be centered
if( abs(leftValue-rightValue)
< centeredThreshold){
dezibot.motion.move();
}else{
if (leftValue > rightValue){
dezibot.motion.rotateAntiClockwise();
} else{
dezibot.motion.rotateClockwise();
}
}
dezibot.multiColorLight.setTopLeds(BLUE);
break;
case IR_LEFT:
dezibot.motion.rotateAntiClockwise();
dezibot.multiColorLight.setTopLeds(RED);
break;
case IR_RIGHT:
dezibot.motion.rotateClockwise();
dezibot.multiColorLight.setTopLeds(GREEN);
break;
case IR_BACK:
if(leftValue > rightValue){
dezibot.motion.rotateAntiClockwise();
} else {
dezibot.motion.rotateClockwise();
}
dezibot.multiColorLight.setTopLeds(YELLOW);
break;
}
//delay(100);
}

View File

@ -0,0 +1,156 @@
#include <Dezibot.h>
#include <arduinoFFT.h>
#include <rom/ets_sys.h>
const uint16_t samples = 256; //This value MUST ALWAYS be a power of 2
const int centeredThreshold = 50 ;
//const float signalFrequency = 1000;
const float samplingFrequency = 4000;
float vReal[4][samples];
float vImag[4][samples];
#define SCL_INDEX 0x00
#define SCL_TIME 0x01
#define SCL_FREQUENCY 0x02
#define SCL_PLOT 0x03
ArduinoFFT<float> FFT = ArduinoFFT<float>(vReal[0], vImag[0], samples, samplingFrequency); /* Create FFT object */
Dezibot dezibot = Dezibot();
void setup() {
dezibot.begin();
Serial.begin(115200);
//dezibot.infraredLight.front.turnOn();
//dezibot.infraredLight.bottom.turnOn();
}
void loop() {
portDISABLE_INTERRUPTS();
for(int i = 0; i < samples; i++){
vReal[0][i] = dezibot.lightDetection.getValue(IR_FRONT);
vImag[0][i] = 0.0;
vReal[1][i] = dezibot.lightDetection.getValue(IR_LEFT);
vImag[1][i] = 0.0;
vReal[2][i] = dezibot.lightDetection.getValue(IR_RIGHT);
vImag[2][i] = 0.0;
vReal[3][i] = dezibot.lightDetection.getValue(IR_BACK);
vImag[3][i] = 0.0;
ets_delay_us(125);
}
portENABLE_INTERRUPTS();
//PrintVector(vReal, (samples>>1), 0);
//PrintVector(vReal, (samples>>1), 0);
float frequency[4];
float magnitude[4];
for(int index = 0; index <4; index++){
FFT.setArrays(vReal[index], vImag[index]);
FFT.windowing(FFTWindow::Rectangle, FFTDirection::Forward); /* Weigh data */
FFT.compute(FFTDirection::Forward); /* Compute FFT */
FFT.complexToMagnitude(); /* Compute magnitudes */
FFT.majorPeak(&frequency[index],&magnitude[index]);
if(abs(frequency[index]-1147)>10){
magnitude[index] = 0;
}
Serial.print(index);
Serial.print(":");
Serial.print(frequency[index]);
Serial.print(",");
Serial.print(index+4);
Serial.print(":");
Serial.print(magnitude[index]);
if(index < 3){
Serial.print(",");
}
Serial.println();
}
//================================================
float leftValue = magnitude[1];
float rightValue = magnitude[2];
switch(brightest(magnitude)){
case IR_FRONT:
//correct Stearing to be centered
if( abs(leftValue-rightValue)
< centeredThreshold){
dezibot.motion.move();
}else{
if (leftValue > rightValue){
dezibot.motion.rotateAntiClockwise();
} else{
dezibot.motion.rotateClockwise();
}
}
dezibot.multiColorLight.setTopLeds(BLUE);
break;
case IR_LEFT:
dezibot.motion.rotateAntiClockwise();
dezibot.multiColorLight.setTopLeds(RED);
break;
case IR_RIGHT:
dezibot.motion.rotateClockwise();
dezibot.multiColorLight.setTopLeds(GREEN);
break;
case IR_BACK:
if(leftValue > rightValue){
dezibot.motion.rotateAntiClockwise();
} else {
dezibot.motion.rotateClockwise();
}
dezibot.multiColorLight.setTopLeds(YELLOW);
break;
}
}
photoTransistors brightest(float *magnitudes){
int pos;
float maxMagnitude = 0;
for(int index = 0; index <4; index++){
if (magnitudes[index] > maxMagnitude){
pos = index;
maxMagnitude = magnitudes[index];
}
}
switch (pos) {
case 0:
return IR_FRONT;
case 1:
return IR_LEFT;
case 2:
return IR_RIGHT;
case 3:
return IR_BACK;
}
}
void PrintVector(float *vData, uint16_t bufferSize, uint8_t scaleType)
{
for (uint16_t i = 0; i < bufferSize; i++)
{
float abscissa;
/* Print abscissa value */
switch (scaleType)
{
case SCL_INDEX:
abscissa = (i * 1.0);
break;
case SCL_TIME:
abscissa = ((i * 1.0) / samplingFrequency);
break;
case SCL_FREQUENCY:
abscissa = ((i * 1.0 * samplingFrequency) / samples);
break;
}
Serial.print(abscissa, 6);
if(scaleType==SCL_FREQUENCY)
Serial.print("Hz");
Serial.print(" ");
Serial.println(vData[i], 4);
}
Serial.println();
}

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,23 @@
#include "Dezibot.h"
Dezibot dezibot = Dezibot();
void setup() {
// put your setup code here, to run once:
dezibot.begin();
dezibot.multiColorLight.turnOffLed();
}
void loop() {
// put your main code here, to run repeatedly:
dezibot.display.clear();
int light = dezibot.lightDetection.getValue(DL_FRONT);
dezibot.display.print(light);
if(light > 2000) {
dezibot.motion.move();
} else {
dezibot.motion.rotateClockwise();
}
delay(100);
}

View File

@ -8,14 +8,9 @@ void setup() {
void loop() {
// put your main code here, to run repeatedly:
dezibot.display.print("Starte Nachricht!");
delay(2000);
dezibot.multiColorLight.setLed(ALL,dezibot.multiColorLight.color(100,0,0));
delay(2000);
dezibot.multiColorLight.turnOffLed(ALL);
delay(2000);
//dezibot.display.print("Starte Nachricht!");
//delay(2000);
//dezibot.display.clear();
dezibot.display.clear();
// T
longSignal(1);
@ -46,13 +41,9 @@ void loop() {
longSignal(1);
shortSignal(1);
dezibot.display.print("Ende Nachricht!");
delay(2000);
dezibot.multiColorLight.setLed(ALL,dezibot.multiColorLight.color(0,255,0));
delay(2000);
dezibot.multiColorLight.turnOffLed(ALL);
delay(2000);
//dezibot.display.print("Ende Nachricht!");
//dezibot.display.clear();
dezibot.display.clear();
}
void shortSignal(int count){

View File

@ -0,0 +1,14 @@
#include <Dezibot.h>
Dezibot dezibot = Dezibot();
void setup() {
dezibot.begin();
}
void loop() {
if(dezibot.motion.detection.isShaken()){
dezibot.display.clear();
dezibot.display.print(random(1,7));
delay(1000);
}
}

View File

@ -0,0 +1,14 @@
#include <Dezibot.h>
Dezibot dezibot = Dezibot();
void setup() {
dezibot.begin();
}
void loop() {
for (int i=1; i<=10; i++){
dezibot.display.clear();
dezibot.display.print(i);
delay(1000);
}
}