Skip to content

Instantly share code, notes, and snippets.

@dropmeaword
Last active November 24, 2017 23:52
Show Gist options
  • Save dropmeaword/1665c5bbabdd0f20ba1bb63f6e462481 to your computer and use it in GitHub Desktop.
Save dropmeaword/1665c5bbabdd0f20ba1bb63f6e462481 to your computer and use it in GitHub Desktop.
This is the shell code for the shy bot of Unit #3 - MDD
int sWAITING = 0;
int sMOVING = 1;
int sSAFETY = 3;
int currentState = sWAITING;
int eyeL = 0;
int eyeR = 0;
int pinLeftEye = 8;
int pinRightEye = 7;
int motionTime = 1200;
void setup() {
}
void move_bot(int dir, int msec) {
// here we still have to implement the actual motion code
currentState = sMOVING;
}
void look_araound() {
eyeL = analogRead( pinLeftEye );
eyeR = analogRead( pinRightEye );
// NOTE: the reading will probably be a bit chaotic, and might be
// different for each sensor, so we need to normalize them.
}
void i_am_safe_now() {
currentState = sSAFETY;
}
void loop() {
look_around();
// if both eyes read below 20% light then our current state is sWAITING
// if reading on eyeL is 20% great than reading on eyeR then move to R (for X steps) transititon to stte sMOVING
// if reading on eyeR is 20% great than reading on eyeL then move to L (for X steps) transititon to stte sMOVING
// if I am moving and I reach a spot when the light readings are again below 20% then I go into state sWAITING
if( (currentState == sWAITING) && (eyeL > eyeR) ) {
move_bot(Right, motionTime);
} else ( eyeR > eyeL ) {
move_bot(Left, motionTime);
}
if( (currentState == sWAITING) && ( eyeR < lowLightThreshold ) ) {
i_am_safe_now();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment