Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Pseudocode for ping-pong
if (leftBrightness < rightBrightness && middleBrightness > leftBrightness) {
// Ball is on the left and not the middle
moveLeft();
} else if (rightBrightness < leftBrightness && middleBrightness > rightBrightness) {
// Ball is on the left and not the middle
moveRight();
} else if (middleBrightness < leftBrightness && middleBrightness < rightBrightness) {
// Ball is in the middle
// Wait for it to continue moving and then chase after it.
} else {
// Ball not detected
console.error("Ball not detected");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment