PSoC 5LP Reading Pins

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

I am very new to PSoC, and have very limited experience with C++, and none with C. I am trying to read the signal on a pin and toggle a boolean value to change the blinking speed of an external LED. Here's the code:

   

int main()
{
    bool button1;
    LCD_Char_Start();
    LCD_Char_PrintString("Hola Mundo!");

   


    for(;;)
    {
        if(CyPins_ReadPin(Pin_1_0) !=0) {
            button1 = !button1;
            CyDelay(100);
        }
        if(button1) {
            CyDelay(1000u);
        } else {
            CyDelay(250u);
        }
        P0_0_Write(!P0_0_Read());
    }
}

   

The CyPins thing I got from another thread and the LCD stuff is from the Hello World example project. The LCD doesn't work though. I also kept include project.h and added stdbool.h for booleans. Any idea what I might be doing wrong?

   

Edit: I should probably mention I have the CY8CKIT-059 and if it matters to mention too, the chip is the CY8C5888LTI-LP097.

0 Likes
8 Replies
lock attach
Attachments are accessible only for community members.
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Here is a PDF on how to use pins .  It is written for the PSOC 4 but applies to your device as well.  Also don't forget to check the schematic for your kit to insure that there is not a capacitor or other device on your chosen pins that may interfere with the design. 

0 Likes
lock attach
Attachments are accessible only for community members.
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

You can do it all in hardware with out any code.  Check out this example. I am running PSOC 4.0

0 Likes
Anonymous
Not applicable

My goal is to do it in code so I can learn C though. I want to be able to make an LCD have a menu that I can go through with buttons for a signal generator, but for now, the LED is all, the basics.

   

Edit: Sorry if I sounded harsh, but I was a bit peeved after trying at the LCD with example code. Thanks for the input 🙂

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Can you please post your complete project, so that we all can have a look at all of your settings. To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file.

   

 

   

Bob

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Here you go Bob, by request, the Workspace Bundle.

0 Likes
Anonymous
Not applicable

You guys may be glad to know I got the LCD working, I had the first two pins on the port, pins 4 and 5 on the 44780 display swapped. But the problem with pin reading still stands ;(

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Yoy may use Pin_2_Read() which is independent from changing the underlying real pin. When the pin is connected to a switch that connects the pin to GND (which is the usual/preferred case) the pin should be configured as resistive pull up, initial drive high.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Thanks so much Bob! 😄

   

I was in Toronto all yesterday so I couldn't reach the web. Now I got to decide what to make my PSoC do 🙂

0 Likes