1
SKILL
LEVEL
Ringo Educational Guide Rev04.1 ~ Plum Geek
Using Ringo’s Light Sensors
Now we’ll talk about what is happening. You’ll notice a few differences in this
example.
Firstly, we placed the
digitalWrite(Source_Select, HIGH);
in the
setup()
function
because in this case, it only really needs to run once (as we’re not switching to
read the lower sensors in this case). This is fine to do, but you probably want to
include this in your main
loop()
function if you’re reading both top and bottom
sensors.
We first start by turning off all the pixels. The next step
delay(2);
is super
important. The light sensors are amplified through a part called an “op-amp”, and
this particular op-amp takes about a millisecond to adjust to the lower light level
after Ringo’s eyes are turned off. By delaying 2 milliseconds, we can be certain
that Ringo is no longer seeing any “after glow” from having his eyes turned on. As
soon as this delay is complete, we can go grab the three readings we want with
analogRead()
functions. As soon as the readings are complete, we flip Ringo’s eyes
back on. Once the eyes are back on, we send the serial data of the readings back
to your computer, and finally, we wait a half second before doing it all again.
In the next section, we’ll talk about reading Ringo’s bottom sensors which can be
used to sense lines and edges.
// ... continued from previous page ....
SetPixelRGB( 4, 220, 30, 160);
//set pixel 4 (Right eye)
SetPixelRGB( 5, 220, 30, 160);
//set pixel 5 (Left eye)
RefreshPixels();
//turn on the pixels
Serial.print(sensorLeft); //print sensorValue through serial port
Serial.print(“ “); //print a couple blank spaces
Serial.print(sensorRight); //print sensorValue through serial port
Serial.print(“ “); //print a couple blank spaces
Serial.print(sensorRear); //print sensorValue through serial port
Serial.println(); //print a blank line feed
Serial.println(); //print a blank line feed
delay(500); //wait a half second before looping
}