Page 195 - 15 Dangerously Mad Projects for the Evil Genius
P. 195

172      15 Dangerously Mad Projects for the Evil Genius










































         Figure 13-20  A chart showing ambient light compensation


        means that the IR LED is doing its work and        Control Software
        shining a bright beam into the phototransistor, so
                                                           If you have not used Arduino before, then
        we are naturally keeping the influence of external
                                                           hopefully you will be impressed by the simplicity
        light fairly low.
                                                           and power of this little microcontroller board. Let’s
           The difference line remains fairly flat, which is
                                                           have a look at the program that controls the
        what we want, and means that external influences
                                                           levitation machine. (See Listing 13-1.)
        such as turning on a bright light near the levitator
                                                             The Arduino boards use the C programming
        (between samples 43 and 90) and shading it with a
                                                           language. It is beyond the scope of this book to
        large box (between samples 118 and 180) were
                                                           explain the whole C language, but if you have a
        both compensated for.
                                                           basic familiarity with programming, you should be
           Interestingly, you can see the mains frequency
                                                           able to understand the following explanation.
        flicker from that first event, where the brightness
                                                             The program starts with some variable
        of the lamp fluctuated with the mains frequency.
                                                           declarations. The lines that start with a // denote
        This leaves a small trace on the compensated
                                                           comment lines that explain what is happening.
        signal, but not enough to worry about.
                                                             We then have a “setup” function that says how
                                                           the various connections on the board are to be
                                                           used, and sets the baud rate for communication
                                                           with the Serial Monitor. A message saying what
   190   191   192   193   194   195   196   197   198   199   200