Created
July 4, 2018 03:20
-
-
Save e-Gizmo/20849c8112293348ebcc798a27ea6cd1 to your computer and use it in GitHub Desktop.
For PBOT2018 Avoid collision sketch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/********************************************** | |
e-Gizmo PBOT Controller - AVOID COLLISION.ino | |
This is for collsion sample sketch to avoid | |
crashing on the wall or any objects that blocking | |
way of the PBOT. | |
Reading the 3channel Collision sensors: | |
PBOT.COL1_RIGHT(); | |
PBOT.COL2_CENTER(); | |
PBOT.COL3_LEFT(); | |
Output reads: | |
No object detection = 0 or LOW; | |
Object detected = 1 or HIGH; | |
Codes by | |
e-Gizmo Mechatronix Central | |
http://www.e-gizmo.net | |
June 5,2018 | |
************************************************/ | |
#include "eGizmo_PBOT2018.h" | |
#include <Wire.h> | |
eGizmo_PBOT2018 PBOT; | |
void setup() { | |
Serial.begin(9600); | |
Wire.begin(); | |
PBOT.BEGIN(); | |
PBOT.ALLON(); | |
PBOT.SPEED(MOTOR_BOTH, 120); | |
} | |
void loop() { | |
if(PBOT.COL2_CENTER()){ //center object detection | |
change_direction(); | |
} | |
delay(200); | |
} | |
//Sample Function for changing directions | |
void change_direction(void) { | |
boolean cw = HIGH; | |
PBOT.DIRECTION(MOTOR_BOTH, MOTOR_REV); | |
delay(500); | |
if (cw) { | |
cw = false; | |
PBOT.DIRECTION(MOTOR_A, MOTOR_FWD); | |
} else { | |
cw = true; | |
PBOT.DIRECTION(MOTOR_B, MOTOR_FWD); | |
} | |
delay(500); | |
PBOT.DIRECTION(MOTOR_BOTH, MOTOR_FWD); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment