Skip to content

Instantly share code, notes, and snippets.

@RobotGrrl
Created July 3, 2011 21:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RobotGrrl/1062609 to your computer and use it in GitHub Desktop.
Save RobotGrrl/1062609 to your computer and use it in GitHub Desktop.
RoboBrrd LDR Behaviour
void ldrBehaviour(int ldrL, int ldrR) {
// Current angle of X (leftright aka pan)
int current = leftright.read();
// Neutral State
if(ldrL < (ldrR+thresh) && ldrL > (ldrR-thresh)) {
if(current < 90) {
leftright.write(current+1);
} else if(current > 90) {
leftright.write(current-1);
}
}
// Right is bright
else if(ldrL > (ldrR+thresh)) {
if(current < 180) {
leftright.write(current+1); // Going towards 180
} else {
for(int i=0; i<6; i++) {
moveRightWing(!alternate);
alternate = !alternate;
delay(80);
}
rightwing.write(20);
}
}
// Left is bright
else if(ldrL < (ldrR-thresh)) {
if(current > 0) {
leftright.write(current-1); // Going towards 0
} else {
for(int i=0; i<6; i++) {
moveLeftWing(!alternate);
alternate = !alternate;
delay(80);
}
leftwing.write(90);
}
}
// Update the current
current = leftright.read();
// Left side
if(current < 90) {
int c0 = 90-current;
int c1 = (20*c0)/90;
int c2 = 100-c1;
updown.write(c2);
}
// Right side
else if(current > 90) {
int c0 = 90-(180-current);
int c1 = (20*c0)/90;
int c2 = 100-c1;
updown.write(c2);
}
// Home position
else {
updown.write(100);
}
delay(10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment