First, your project is using both an old PSoC3 device (ES2 version) and old components. You should upgrade to the recent version of Creator (2.2) - or are you bound to the old PSoC3 version? (the replacement program for old PSoC3 boards has unfortunately been shut down as of now).
But to your question: your circuit should work, but the input pin must be configured as digital input pin. When you try to compile the design, the error message gives it away:
Terminals "LED.y_0" connected to signal "Net_33" have mismatching types
To drive a digital signal (your output pin) you need a digital signal. This can be either the input pin directly, or you need to use a comparator to convert the analog input to a digital signal.
Which Development kit are you using? Are you sure the pins are assigned correctly? (I cannot remember a kit where the LEDs are on port 2 and an input button is on port0)
Since I didn't look at your code before: you don't need it. All the functionality is already provided in the hardware :)
But when you want to solve it in software:
- change the input pin to digital, as before
- remove the wire between the two pins
- set both pins not to have "HW connection" (that means they are on its own, and have no further connection inside of the PSoC hardware)
- the code uses wrong logic - you check in both if-statements for the same condition, but the second one should be reversed. Better to use if-else.
- use Pin_Write to set the value of an output port. Pin_SetDriveMode just changes the way the pins behaves, but doesn't set it low or high (please read the data sheet for the pin component)
I am using psoc 3 first touch starter kit.
I am bound to the old version unfortunately.
basically i just need to know how to read the input from a button.
when i know the right command i will use it to navigate in my menu.
i have change it to a digital input now. it compiles fine now but the button has no effect. The led keeps lit.
If you are bound to the old PSoC3, you cannot update the Creator version :(
Do you now have a solution completely in hardware, or do you still use the software-part?
When you code just wants to read the button state, you can use the debouncer component, and feed its output to a status register. Then your code can read this register, and be happy. Same goes for the LED - just add a control register (connected to the LED), and write to that.
I just tested the hardware-only solution with my -050 kit, and it works (just needed to change the input to pullup, since the button here is connected to ground, not Vcc). It works without problems. But I checked the schematic for the FTK, and it shows the push-button connected to P15. So this might be the culprit...
This here is just a part of the project.
I am making a menu so the buttons is for navigating in my menu.
but i cant get the buttons to react so i just tried to make a simple project as i uploaded here.
the program i uploaded should just turn on the led when i press the button.
on my board on pin P15_3 i have a button. thats way i have attached pin_1 there.
Does the test-project work when using the button on P15 (which is the button already exisitng on the board)? If yes, the maybe your button setup is wrong... As I said - I tested the pure hardware solution (while commenting out the whole code in the while()-loop), and it works.
Some observations -
1) Your project will not compile because you configed input pin as analog and
connected it to a pin configed as digital. Input pin should be digital, with pullup
(since your switch connects to ground). When you compile, there is a notice
tab at bottom of output window, that shows all errors. You can double click an
error and Creator, most of the time, will show you on schematic, or in code,
where problem lies.
2) As hli pointed out, you should use glitch module to debounce pin.
3) You have in code a reference to Pin_1_1, but no pin on schematic. So error
produced, eg. a reference that does not exist.
4) This code -
if (CyPins_ReadPin(Pin_1_1)) // if pin_1 equals high
LED_SetDriveMode(LED_DM_STRONG); //Turns LED ON
if (CyPins_ReadPin(Pin_1_0)) // if pin_1 equals low
LED_SetDriveMode(LED_DM_STRONG); //Turns LED ON
should be changed to -
if ( CyPins_ReadPin( Pin_1_1 ) ) // if pin_1 equals high
LED_Write( 1 ); //Turns LED ON
LED_Write( 0 ); //Turns LED Off
You were setting drive mode, not pin logical value.
I have an error in prior post, change the first code line to
if ( CyPins_ReadPin( Pin_1_0 ) ) // if pin_1 equals high
I had the wrong pin name, thats the corrected name of the input pin you
created, and Creator choose when routing. You can change the physical
pin by double clicking *.cydwr file in worksapce, and pick pins tab. If you
do the pin name will stay the same, but the physical pin will take on the
new setting you choose. Note generally speaking, to eliminate physical
vs logical pin, name the pin something meaningful, like "LEDbutton" in
sorry for the delay of answering.. thankyou for the replays. I Have got it to work now. I found the command i was looking for.