Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

Share this Page URL

The Flight > Measuring Temperature - Pg. 184

184 Chapter 10 Steps 3.5 and 3.6 are all about displaying and differentiating the two LEDs. To show both LEDs on the display bar we could simply add the two binary patterns mallet and mole but it would be very hard for the player to tell who is who. To represent the mole LED with a dimmer light, we can alternate cycles of the main loop where we present both LEDs and cycles where only the mallet LED is visible. Since the main loop is executed hundreds of thousands of time per second, our eye will perceive the mole LED as dimmer, proportionally to the number of cycles it is missing. For example: if we add the mole LED only once every 16 cycles, its apparent brightness will be only one-sixteenth of that of the mallet LED. The counter c, constantly incremented in 3.6, helps us to implement this mechanism. In 3.5 we look only at the 4 lsb of the counter (0..15) and we add the mole LED to the display only when their value is 0b0000. For the remaining 15 loops, only the mallet LED will be added to the display. Build the project and download it to the Explorer16 board. You will have to admit it, it's much more entertaining now! Measuring Temperature Moving on to more serious things, there is a temperature sensor mounted on the Explorer16