NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Project Help and Ideas » What I would like to Have
December 07, 2009 by timk |
I am trying to come to grips with all this stuff. Don't get me wrong I think this kit is the greatest thing since sliced bread. But after burning up most of my first kit just hooking up a power supply I have been a little afraid of experimenting. I now have it back together and working as expected. I have power supply connected and the backlight on the display working. What I would like to have is a simple example of A button being pressed, waiting a length of time and turning on an LED. I would like the c source code and the make file and any other files needed all with comments explaining what each line is for. Along with instructions for connecting the Switch and the LED. I know that most of this is probably simple and covered in the tutorials. But to me it would be simpler/safer if I had all this info in one spot. And with this information I think I can learn and build from it. I have seen the simple blinking led thread on the site but was not sure how to create the Makefile. I think most of the compile errors I recieved was because of the different include files. Thanks for any help Timk |
---|---|
December 07, 2009 by FWSquatch |
I don't have my stuff in front of me, but here is some code that should do what you want. The LED anode should connect like this: anode to pin 27 (row 12 of your breadboard on the right side) and the cathode should hook up to ground. I can't exactly remember how the Nerdkits pushbutton hooks up off the top of my head, but basically, it should hook up to pin 28 (row 11 on the right side of your breadboard) and the ground. The following is the code for a file named button_led_blink.c. Create it and then save it into the led_blink folder
Next, go into your Makefile and replace all of the "led_blink" with "button_led_blink". It should look like this:
Now you are ready to make. |
December 07, 2009 by timk |
Thanks, This is perfect Worked great, I have already been playing around with code to work more LEDs and am now trying to add the LCD stuff to display which Led is on and off. Thanks again Happy Holidays TimK |
December 07, 2009 by FWSquatch |
Glad to hear it! I wrote it at work and was worried that I'd put a typo in it that would make it all grind to a halt. :) |
July 12, 2011 by uml_12 |
I'm having a small issue with this code that is a reoccurring problem in most of my projects. I have copy/pasted the code exactly as above and loaded it onto my 168. Connected to Pin28 is the switch that connects to ground when pressed. Connected to Pin27 is a resistor followed by an led anode. The cathode is connected to ground. Now I run the code and for some reason the led is already on. When the button is pressed, the led stays on briefly, turns off and then turns back on. So I modified the code after line 13 to do: PORTC &= ~(1<<PC4); Basically I want to have the led off before the switch is pressed. I run this new code and nothing changes. This has been reoccurring in a lot of my projects. I feel like I'm overlooking a basic concept. Any possible solution? Here is the code I'm using .. not much different than yours:
|
July 12, 2011 by Noter |
Are you missing the braces to block the indented code for your if statement? |
July 12, 2011 by Noter |
Also it takes a few uSec for the voltage to rise after enabling the pull-up so you may need to delay briefly or your 1st time in the loop may see the pin still grounded. And there is nothing to return to so you don't need the return 0; at the end of main.
|
Please log in to post a reply.
Did you know that you can build an analog amplifier with one transistor and a few resistors? Learn more...
|