NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Project Help and Ideas » Pushbutton state displayed by the LCD
January 15, 2011 by SpaceGhost |
Okay, I've been at it again. Now I'm trying to program my MCU to display on the LCD a button's function when pressed (on) and its state when it is not pressed (off), and at the same time turn on an LED with the same button (LED is off when the button is not pressed). Here is what I've done so far:
Obviously this will be for a transmitter circuit. The LED part works fine - LED is off, and turns on when the button is pressed. LED returns to off when button is released. The LCD part works too, sort of - "STAND BY" is displayed on line one of the LCD when the button is not pressed. "TRANSMITTING" is then displayed on line one when the button is pressed... However "TRANSMITTING" is displayed on line three all the time, regardless of the button's on/off state. I've tried several different things and the code above is the closest I've came to getting it work the way I want. I'd like to be able to put the information on the LCD on another line if I decide later that's where I want it instead. I don't want to just "cover" line three... (I would like to still be able to possibly use other buttons to display other information on other lines.) Could someone give me a clue as to how to fix my code? |
---|---|
January 15, 2011 by SpaceGhost |
Hey, I think I know what I did wrong!! I'll post later tonight or tomorrow. Don't give it away to me yet! Dave |
January 15, 2011 by SpaceGhost |
Okay, it's working right now... Those darned brackets!!! It seems that I forgot a few of them (again!). Here's the fixed code, comments corrected also:
Feels great to finally figure something out on my own. I still have a long way to go to fully understanding this stuff! I'm still just looking at other stuff (code) to figure out things. And that helps. Now I really want to dig deeper... Still, I'd like to ask the experts: Did I do it right? Is there a better, or more proper way of doing it? I'm open to any suggestions or critique, as always. Dave |
January 16, 2011 by Rick_S |
Glad to see you got it on your own. I knew you could if you just looked at it long enough. Gives you a good feeling of accomplishment doesn't it. I know it does when I figure out bugs in my projects. As for the code, it looks fine. Rick |
January 21, 2011 by SpaceGhost |
Okay, another question related to this subject. Let's say that I wanted to add another button and make PC3 that button's input. The variable that I use for that pushbutton input would be "freq_display." Now, I want the program to display "433 Mhz" on the second line, but ONLY when BOTH switches are closed (PC2 and PC3) at the same time. I still want "TRANSMITTING" to display if only the switch on PC2 is closed... I guess what I'm asking is - How do I "and" two inputs to produce an output, which in this case is a message on another line on the LCD? (Hope I've explained this right!) I'm seriously pretty clueless on this one. Dave |
January 21, 2011 by hevans (NerdKits Staff) |
Hi SpaceGhost, I think you can take care of something like this with a simple if statement. In much the same way you "checked" the state of one pin, you can check and save the state of your second pin. It would look something like this.
Note that all I did was grab the two states and then write a more complicated if statement that checked both inputs and ANDed the results. You could add and else statement that would fire when either input is 0, or you could add more if statements that check the individual buttons. Hope that helps. Humberto |
January 21, 2011 by SpaceGhost |
This works. I had tried something similar but didn't enclose both sets of parenthesis in another set of parenthesis. Except that "433 Mhz" on lcd line two stays on the display after the button has been released... I figure another if statement such as
Would then work... But what command would I put in to replace "// turn off lcd_line_two", to actually turn off the line two message? |
January 21, 2011 by SpaceGhost |
Works. The five spaces cover the "433 Mhz" phrase on the LCD when both buttons are in their off state. I was just wondering if there was a better way. Dave |
January 21, 2011 by SpaceGhost |
I've looked at some "else" statements. I need to study them some more and how they are used... |
Please log in to post a reply.
Did you know that you can use printf and scanf functions to talk to your computer from your USB NerdKit? Learn more...
|