2
SKILL
LEVEL
Ringo Educational Guide Rev04.1 ~ Plum Geek
Using Ringo’s Edge Sensors
Using the bottom light sensors...
The bottom sensors can be read directly easily enough and used directly in your
program. Consider this example:
#include “RingoHardware.h” //include Ringo background functions
void setup(){
HardwareBegin(); //initialize Ringo’s circuitry
PlayStartChirp(); //play startup chirp and blink eyes
}
int leftOn, leftOff, rightOn, rightOff, rearOn, rearOff; //declare variables
int leftDiff, rightDiff, rearDiff;
//more variables
void loop(){
digitalWrite(Source_Select, LOW);
// select bottom light sensors
digitalWrite(Edge_Lights, HIGH);
// turn on the IR light sources
delayMicroseconds(200);
// let sensors stabilize
leftOn = analogRead(LightSense_Left);
// read sensors w/ IR lights on
rightOn = analogRead(LightSense_Right);
// read sensors w/ IR lights on
rearOn = analogRead(LightSense_Rear);
// read sensors w/ IR lights on
digitalWrite(Edge_Lights, LOW);
// turn off the IR light sources
delayMicroseconds(200);
// let sensors stabilize
leftOff = analogRead(LightSense_Left);
// read sensors w/ IR lights off
rightOff = analogRead(LightSense_Right); // read sensors w/ IR lights off
rearOff = analogRead(LightSense_Rear);
// read sensors w/ IR lights off
leftDiff = leftOn-leftOff;
// subtract out ambient light
rightDiff = rightOn-rightOff;
// subtract out ambient light
rearDiff = rearOn-rearOff;
// subtract out ambient light
// ... continued next page ...
// turn the page :-p