2Dezibot dezibot = Dezibot();
7 // put your setup code here, to run once:
10 //dezibot.motion.move();
11 //analogWrite(11, 2000);
12 //analogWrite(12, 2000);
14uint16_t leftDuty= baseDuty;
15uint16_t rightDuty = baseDuty;
16unsigned long previous = millis();
17unsigned long current = millis();
18long averageZRotation = 0;
19long averageXAccel = 0;
28 // put your main code here, to run repeatedly:
30 IMUResult result = dezibot.motion.detection.getRotation();
31 averageXAccel += dezibot.motion.detection.getAcceleration().x;
32 averageZRotation += result.z;
33 //Serial.println(result.z);
34 if (result.z > threshold){
36 } else if(result.z < -threshold) {
40 if ((current - previous) > interval){
41 //averageZRotation = averageZRotation / resultcounter;
42 difference = abs(left-right);
45 } else if(difference>20){
47 } else if(difference >15){
49 } else if(difference > 10){
55 //Serial.println(averageZRotation);
56 dezibot.display.clearDisplay();
57 dezibot.display.setCursor(0, 0);
58 dezibot.display.setTextColor(WHITE);
59 dezibot.display.setTextSize(2); // Draw 2X-scale text
60 dezibot.display.println(averageZRotation);
61 //dezibot.display.println(resultcounter);
62 dezibot.display.print(left);
63 dezibot.display.print(" ");
64 dezibot.display.println(right);
65 if(left>right){ //rotates anticlock
67 rightDuty-=changerate;
68 } else if(left<right){
70 rightDuty+=changerate;
72 dezibot.motion.left.setSpeed(leftDuty);
73 dezibot.motion.right.setSpeed(rightDuty);
74 dezibot.display.println(leftDuty);
75 dezibot.display.println(rightDuty);
76 dezibot.display.display();