The basic concept to this first example, is simple. You have a red LED. You push a button to toggle the light on or off.
Here is the first project. The red circle in the bottom right is the push button (it’s a temporary switch… you hold it down if you want the light to stay off).
The red-orange dot on the left is my LED (it was on when I took the picture). The circuitry at the top of the breadboard is the Experimenters board. It plugs directly into the breadboard, and has a NXT compatible jack.
I ran into a few issues with this project. Namely… the LED wouldn’t light up.
Since I’m new to electronics, I started with step 1 in debugging. Double and triple checking to make sure that the circuit was created properly. Some components can be connected any way you want (like jumper wires and resistors). Others have polarity, and can only be connected one way (like the switch and the LED).
After much checking and re-checking, everything was fine. So my next thought, was I had a bad breadboard (It was a new board that came with the Experimenters Kit). I swapped everything over to one of my other breadboards. Still no light.
My next thought, was either the Experimenter Prototype board was bad, or it was the code. Since it came from HiTechnic, and I assumed they tested everything first, I started checking code.
First thing I noticed, is that Xander wrote the tutorials for HiTechnic for this. From what little I know of Xander, I know he tested the code before it became a tutorial, so my best guess, is something changed between the version of RobotC that was originally used, and the version (2.02) I’m currently using.
The example code displayed the value for the button on the screen. I noticed it was 0 for when the button wasn’t pushed, and –1 for when the button was pushed.
However, the code was looking to see if the value was less than 512 to turn off the LED, and if it was more than 512, it turned the LED on.
They didn’t match. So, I just changed the code to check for less than 0. If it’s less than 0, turn the LED on. Otherwise, turn it off.
TADA! Works.
I’ll dig later into why it changed the values. I’ve had some fun today learning a few very basic electronics bits, and digging into debugging some RobotC.
1 response so far ↓
1 RobotC – Mini Tutorial #1 – Displaying Battery Power | Brick Labs // May 4, 2010 at 9:25 pm
[...] RSS ← Experimenters Kit – RobotC Example 1 [...]
Leave a Comment