PSoC5LP Lab 02: Switch and LED Control with C Code

Introduction

Welcome to this hands-on lab focused on basic input/output (I/O) control using the PSoC 5LP microcontroller on the CY8CKIT-059 development board. This lab introduces you to controlling LEDs and reading switch inputs—fundamental skills in embedded system design.

You will progressively build up your programs through three experiments:

  • blinking an LED using software delay,
  • controlling an LED via a push-button switch,
  • and toggling an LED based on switch press events using falling-edge detection with debounce.

By the end of this lab, you will understand GPIO configuration, input reading, output control, software debouncing, and edge detection — all using PSoC Creator 4.4 and the CY8CKIT-059.

Objective

  • Learn to configure digital GPIO pins for output (LED) and input (switch).
  • Implement software-controlled LED blinking using a delay function.
  • Read the state of a push-button and control an LED accordingly.
  • Understand and implement software debouncing to handle mechanical switch noise.
  • Detect falling-edge events (button press) to toggle the LED state.
  • Utilize PSoC Creator 4.4 components and workspace tools effectively.

Overview

In embedded systems, switches typically serve as input devices, while LEDs act as output indicators to visually reflect the system’s status. In this experiment using PSoC Creator and C code, the LED's behavior is controlled by configuring specific GPIO pins—one to receive the switch input and another to drive the LED. When the switch is pressed, it sends a signal that triggers the microcontroller to change the LED's state.

Required Reading Materials

Required Components

If you use the Cypress CY8CKIT-059 Kit, the onboard LED and button will be used in this lab.

The following components are required for this lab.

Button Small 64 Push Button (Optional, can use onboard components) x 1
Resistor 64 Resistor 200ohm (if using an external LED) x 1
LED Red 64 Red LED (or onboard LED) x 1

Circuit / Schematic

Procedure

Creating a New Project

  1. Launch PSoC Creator.
  2. Got to File ➤ Open Project ➤ Project/Workspace.
  3. Open the PSoC5LP workspace in the EE4450 folder.
  4. After PSoC Creator opens the workspace, right-click on Workspace 'PSoC5LP' in the Workspace Explorer and select Add ➤ New Project...
  5. Select the correct PSoC5LP device model number, use the "Empty schematic" template, and enter the project name 02_GPIO_CCode.

Adding PSoC Creator Components

Follow the steps below to add components to the TopDesign.cysch in your PSoC Creator project:

  • Add a Digital Input Pin:
    1. Open the component catalog under the Ports and Pins category.
    2. Drag and drop a Digital Input Pin onto the schematic.
  • Add a Digital Output Pin:
    1. From the same Ports and Pins category, select Digital Output Pin.
    2. Drag and drop it onto the schematic.

After completing these steps, you have successfully added both the Digital Input Pin and the Digital Output Pin to your schematic. You can now proceed with configuring the parameters and wiring them as required for the experiment:

Configure the Components

  1. Configure the Digital Input Pin (Pin_1):
    • Click on the Pin_1 component in the schematic.
    • Rename the component to nSW1 to reflect its function as a switch.
    • Set the Drive Mode to Resistive pull-up, which ensures the pin defaults to high when not pressed.
    • Uncheck the box for HW connection to disable the hardware connection, as shown in the diagram.
      Config DigitalInputPin Pin 1 s
  2. Configure the Digital Output Pin (Pin_2):
    • Select the Pin_2 component.
    • Rename it to LED1, indicating that it controls the LED.
    • Uncheck the HW connection box, as the LED will be software-controlled..

The new TopDesign.cysch file is shown below:

Click the Generate Application button to allow PSoC Creator to generate or update the various API files.

Pin Assignment

DevicePort.PinDirectionDrive Mode

Experiments

© 2026 Air Supply Information Center (Air Supply BBS)