mirror of
https://gitlab.dit.htwk-leipzig.de/phillip.kuehne/dezibot.git
synced 2025-07-04 09:41:43 +02:00
added examples to determine direction of light and basic find a friend (wip: needs additional movement functions)
This commit is contained in:
8
example/FindAFriend/FindAFriend/.theia/launch.json
Normal file
8
example/FindAFriend/FindAFriend/.theia/launch.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
|
||||
]
|
||||
}
|
48
example/FindAFriend/FindAFriend/FindAFriend.ino
Normal file
48
example/FindAFriend/FindAFriend/FindAFriend.ino
Normal file
@ -0,0 +1,48 @@
|
||||
#include "Dezibot.h"
|
||||
|
||||
Dezibot dezibot = Dezibot();
|
||||
const int centeredThreshold = 100;
|
||||
|
||||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
dezibot.begin();
|
||||
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(1);
|
||||
}else{
|
||||
if (leftValue > rightValue){
|
||||
dezibot.motion.rotateAnticlockwise(1);
|
||||
} else{
|
||||
dezibot.motion.rotateClockwise(1);
|
||||
}
|
||||
}
|
||||
dezibot.multiColorLight.setTopLeds(BLUE);
|
||||
break;
|
||||
case IR_LEFT:
|
||||
dezibot.motion.rotateAnticlockwise(1);
|
||||
dezibot.multiColorLight.setTopLeds(RED);
|
||||
break;
|
||||
case IR_RIGHT:
|
||||
dezibot.motion.rotateClockwise(1);
|
||||
dezibot.multiColorLight.setTopLeds(GREEN);
|
||||
break;
|
||||
case IR_BACK:
|
||||
if(leftValue > rightValue){
|
||||
dezibot.motion.rotateAnticlockwise(1);
|
||||
} else {
|
||||
dezibot.motion.rotateClockwise(1);
|
||||
}
|
||||
dezibot.multiColorLight.setTopLeds(YELLOW);
|
||||
break;
|
||||
}
|
||||
//delay(100);
|
||||
}
|
35
example/IRDirection/IRDirection/IRDirection.ino
Normal file
35
example/IRDirection/IRDirection/IRDirection.ino
Normal file
@ -0,0 +1,35 @@
|
||||
#include "Dezibot.h"
|
||||
|
||||
Dezibot dezibot = Dezibot();
|
||||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
dezibot.begin();
|
||||
Serial.begin(115200);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// put your main code here, to run repeatedly:
|
||||
Serial.print("Front:");
|
||||
Serial.print(dezibot.lightDetection.getAverageValue(IR_FRONT,20,1));
|
||||
Serial.print(",Left:");
|
||||
Serial.print(dezibot.lightDetection.getAverageValue(IR_LEFT,20,1));
|
||||
Serial.print(",Right:");
|
||||
Serial.print(dezibot.lightDetection.getAverageValue(IR_RIGHT,20,1));
|
||||
Serial.print(",Back:");
|
||||
Serial.println(dezibot.lightDetection.getAverageValue(IR_BACK,20,1));
|
||||
switch(dezibot.lightDetection.getBrightest(IR)){
|
||||
case IR_FRONT:
|
||||
dezibot.multiColorLight.setTopLeds(BLUE);
|
||||
break;
|
||||
case IR_LEFT:
|
||||
dezibot.multiColorLight.setTopLeds(RED);
|
||||
break;
|
||||
case IR_RIGHT:
|
||||
dezibot.multiColorLight.setTopLeds(GREEN);
|
||||
break;
|
||||
case IR_BACK:
|
||||
dezibot.multiColorLight.setTopLeds(YELLOW);
|
||||
break;
|
||||
}
|
||||
//delay(100);
|
||||
}
|
@ -13,6 +13,6 @@ dezibot.multiColorLight.setLed(TOP_RIGHT,dezibot.multiColorLight.color(0,100,0))
|
||||
dezibot.multiColorLight.blink(10,0x00FF0000,BOTTOM,500);
|
||||
|
||||
delay(1000);
|
||||
dezibot.multiColorLight.turnOff(ALL);
|
||||
dezibot.multiColorLight.turnOffLed(ALL);
|
||||
delay(1000);
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
Dezibot dezibot = Dezibot();
|
||||
void setup() {
|
||||
dezibot.begin();
|
||||
Serial.begin(9600);
|
||||
Serial.begin(115200);
|
||||
}
|
||||
void loop() {
|
||||
Serial.println("bla");
|
||||
|
Reference in New Issue
Block a user