3 State LEDs - LED On Full, LED On Half and LED OFFWhilst working on the Voip Desk Phone, I was thinking about what I might want to use the phone's single LED for. I had read about the possibilities of using a LED to detect light level and even communicate. All I wanted to do was indicate the mode the phone was in. I could have just tied it to the power rails, indicating power on, but I connected it to a port and turned it on whenever the handset was picked up. I also wanted to have a way of showing what mode the phone is in, when I get round to implementing the memory dial functions, I will need to be able to tell if the phone is in 'program' mode or not. The VOIP Desk Phone software, like many other programs, spends most of its time in a loop waiting for something to happen. In this case, watching the keypad and the hook switch to see if a key needs sending to the VOIP software. Rather than control the port directly, we can use a static Bit flag to indicate the required state of the LED - on or off. In our 'main loop', we check this Bit Flag and turn the port pin on or off as required. That does not do anything more than give us a virtual LED, we could have just as easily set/reset the port pin. However, if we add another static Bit flag for say 'High/Low' and a counter, things get more interesting. By adding a counter that is incremented each time through the loop, instead of saying 'if LED = ON port B = 0' we can say something like this:- LED ON Full, LED ON Half, LED OFF
tickl++; // Bump counter each time we get here. The above was used to 'test' the function in the VOIP Desk Phone, I'll include it in the next upload of the code once a few other features have been added. Before that, it should be re-coded to take up less space, but as it is, it is easy to see what it is doing. |
![]()
Introduction |