Page 313 - Hacking Roomba
P. 313

294       Part III — More Complex Interfacing





                               Listing 13-4 Continued

                                 pinMode(greenPin, OUTPUT);
                                 pinMode(bluePin,  OUTPUT);
                                 // ...setup continues as before...
                               }
                               void loop() {
                                 updateLEDs();
                                 // ...loop continues as before...
                               }
                               void updateLEDs() {
                                 ledi++;
                                 if( ledi < 255 ) {
                                   redVal   -= 1;   // red down
                                   greenVal -= 1;   // green down
                                 } else if( ledi < 255*2 ) {
                                   redVal   += 1;   // red up
                                   blueVal  -= 1;   // blue down
                                 } else if( ledi < 255*3 ) {
                                   greenVal += 1;   // green up
                                   blueVal  += 1;   // blue up
                                 } else {
                                   ledi = 0;  // reset
                                 }
                                 analogWrite(redPin,   redVal);  // write brightness vals to
                               LEDs
                                 analogWrite(greenPin, greenVal);
                                 analogWrite(bluePin,  blueVal);
                               }





                     Summary

                             Adding a brain to Roomba is one of the most fun things you can do to it. When you have a
                             microcontroller on it that you can reprogram and add new sensors and actuators to, the
                             Roomba becomes a truly interesting robotics platform. Both the Basic Stamp and Arduino
                             enable you to read and control not only digital transducers like switches and lights, but analog
                             ones as well. If you’ve looked over the Stamp and Arduino web sites, you’ve no doubt seen
                             many of the other interesting devices you could hook up to Roomba. Add servos to Roomba to
                             give it arms, or add microphones to give it ears. Make it come to you when you whistle for it.
                             The add-on possibilities are limitless.
                             If you’ve not had much experience with microcontrollers before this, you now know about two
                             of the friendliest yet most powerful embedded development systems out there. The Basic Stamp
                             has a great library of tools and techniques developed from over a decade of work by enthusiastic
   308   309   310   311   312   313   314   315   316   317   318