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

106       15 Dangerously Mad Projects for the Evil Genius


        and 7 is a three-bit number (three binary digits).  arrive at the motor. You could imagine this as a
        Each of these digits can be 1 or 0, which is on or  child sitting on a swing. If you just give the child
        off. So a number 7 in decimal is actually 111 in   short pushes, they will not swing as high as if you
        binary, which means that all three colors would be  give the child a longer push.
        on, making the LED appear white.                     In a motor, the motor either receives full power
           The expression:                                 or no power, in pulses that arrive at perhaps a
                                                           thousand times per second. The motor has no time
         !(color & 2)
                                                           to fully stop when the power is off, so the overall
                                                           effect is that the speed of the motor is controlled
        will evaluate to 0 if the second bit of the color
                                                           smoothly.
        number is set (green), and 2 if it is not. This may
        seem the wrong way around, but the LEDs are
        common anode, which means they turn on when
                                                           Summary
        the output pins are at 0V rather than at 5V.
           The allOff function simply iterates over every  This project could be scaled up to use a bigger
        LED pin, setting it to 5V.                         number of LEDs, although you would probably
                                                           have to use the Arduino’s bigger brother, the
                                                           Arduino Mega, as this has a lot more input/output
        Motor Controller
                                                           pins on it.
        PWM stands for pulse width modulation, and
                                                             If you search the Internet for “persistence of
        refers to the means of controlling the amount of   vision,” you will find many interesting ideas.
        power delivered to a motor in this case. We use a  People have even displayed video using this
        simple PWM controller built using a 555 timer IC.  approach.
        We will meet the 555 timer again in Chapter 12.
                                                             In the next chapter, we switch our attention to
           PWM controls the power to a motor by            spying.
        lengthening or shortening pulses of power that
   122   123   124   125   126   127   128   129   130   131   132