Dezibot 4
Loading...
Searching...
No Matches
FindAFriend.ino
Go to the documentation of this file.
1#include "Dezibot.h"
2
3Dezibot dezibot = Dezibot();
4const int centeredThreshold = 50 ;
5
6void setup() {
7 // put your setup code here, to run once:
8 dezibot.begin();
9 Serial.begin(115200);
10}
11
12void loop() {
13 int32_t leftValue = (int32_t)dezibot.lightDetection.getAverageValue(IR_LEFT, 20, 1);
14 int32_t rightValue = (int32_t)dezibot.lightDetection.getAverageValue(IR_RIGHT, 20, 1);
15 switch(dezibot.lightDetection.getBrightest(IR)){
16 case IR_FRONT:
17 //correct Stearing to be centered
18 if( abs(leftValue-rightValue)
19 < centeredThreshold){
20 dezibot.motion.move();
21 }else{
22 if (leftValue > rightValue){
23 dezibot.motion.rotateAntiClockwise();
24 } else{
25 dezibot.motion.rotateClockwise();
26 }
27 }
28 dezibot.multiColorLight.setTopLeds(BLUE);
29 break;
30 case IR_LEFT:
31 dezibot.motion.rotateAntiClockwise();
32 dezibot.multiColorLight.setTopLeds(RED);
33 break;
34 case IR_RIGHT:
35 dezibot.motion.rotateClockwise();
36 dezibot.multiColorLight.setTopLeds(GREEN);
37 break;
38 case IR_BACK:
39 if(leftValue > rightValue){
40 dezibot.motion.rotateAntiClockwise();
41 } else {
42 dezibot.motion.rotateClockwise();
43 }
44 dezibot.multiColorLight.setTopLeds(YELLOW);
45 break;
46 }
47 //delay(100);
48}