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

cross mob
David_Zhang
Level 5
Level 5
Distributor - Arrow(GC)
First like received 50 sign-ins 25 sign-ins

      when i use pos4 to driver button , thre seting is below , the button just get the the zero, not get the one ,

i check the io ,it change from3.3 to 0v, i don;t understand wath the pin_read();

as we know it should return one pin status so it must be one or zero,

otherwise waht's means of this below describe , It's very winding.to understand; what's it means???

so it's very not friendly for new developer;

pastedImage_3.png

pastedImage_0.pngpastedImage_1.png

pastedImage_2.png

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

I tried what Bob-san wrote by using CY8CKIT-145-40XX.

The schematic

000-schematic.JPG

The config of SW is

001-pin-config.JPG

main.c

=================

#include "project.h"

int main(void)

{

    uint8_t pin_state ;

  

    CyGlobalIntEnable; /* Enable global interrupts. */

    /* Place your initialization/startup code here (e.g. MyInst_Start()) */

    for(;;)

    {

        pin_state = SW_Read() ;

        LED_Write( pin_state ) ;

    }

}

=================

When I don't touch the SW, LED is off, when I push the SW, LED turns on.

moto

View solution in original post

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

To avoid a floating pin declare it as "Resistive pull up", initial drive mode "high". So the pin will get shortened to ground whenthe button is pressed.

Happy coding

Bob

0 Likes
odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

DavidW.Zhang,

You can use this community component to detect switch buttons events:

ButtonSw32: button switch debouncer component

Screenshot_1.png

ButtonSw_basic_1b.png

/odissey1

0 Likes
Vison_Zhang
Moderator
Moderator
Moderator
First comment on KBA 750 replies posted 250 sign-ins

SW2 connects to a button, so its drive mode should not be configured to Strong mode, connect a strong 1 to external GND directly may damage the silicon because you short internal vddio and external gnd together.

Please configure the pin to resister-pull-up drive mode, you code don't need to change.

0 Likes
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

I tried what Bob-san wrote by using CY8CKIT-145-40XX.

The schematic

000-schematic.JPG

The config of SW is

001-pin-config.JPG

main.c

=================

#include "project.h"

int main(void)

{

    uint8_t pin_state ;

  

    CyGlobalIntEnable; /* Enable global interrupts. */

    /* Place your initialization/startup code here (e.g. MyInst_Start()) */

    for(;;)

    {

        pin_state = SW_Read() ;

        LED_Write( pin_state ) ;

    }

}

=================

When I don't touch the SW, LED is off, when I push the SW, LED turns on.

moto

0 Likes
David_Zhang
Level 5
Level 5
Distributor - Arrow(GC)
First like received 50 sign-ins 25 sign-ins

  TKS everyone , it's ok ,tks;

0 Likes