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

@ -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);
}