2
SKILL
LEVEL
Ringo Educational Guide Rev04.1 ~ Plum Geek
Don’t let this “bit” business scare you though. More advanced programmers
will understand this and can further understand the bit order by studying the
LookForEdge() function notes in the “RingoHardware.h” tab.
For everyone else, we’ve provided a few more functions to evaluate the coded
bits in the value returned by LookForEdge(). Let’s look at an example below and
things will be more clear.
void setup(){
HardwareBegin(); //initialize Ringo’s brain to work with his circuitry
PlayStartChirp(); //Play startup chirp and blink eyes
ResetLookAtEdge();
//Zeros the LookAtEdge() running average
}
char edge;
//define a holder for the value returned by LookForEdge()
void loop(){
edge=LookForEdge();
//Read all sensors, update average, determine if
//if any edges were seen, place the coded binary
//result in the variable “edge”. This “edge” variable
//will be zero if no edge was seen.
if(
FrontEdgeDetected(edge)
){
// do something if either front edge was detected
}
delay(100);
//wait a while before looping
}
Using Ringo’s Edge Sensors
Okay, lets talk about this example. For starters, you should call
ResetLookAtEdge()
once before using the edge functions. This zeros out the running average and
makes sure the memory is clear and ready to take new readings. The variable
“
edge
” is declared before starting the
loop()
function. This will hold the response
returned from
LookForEdge()
.
Once inside the loop, we call
LookForEdge()
, but we don’t call it by itself. We
actually tell Ringo to put the result of
LookForEdge()
in the variable “
edge
”. We can
then pass “
edge
” to “
FrontEdgeDetected()
” which is a function that evaluates if the
bits in “edge” indicate that either of the front edge sensors saw something.