In this project, we'll build an application using the CY8CKIT-050 PSoC 5LP development kit to control the speed and brightness of a blinking LED using a potentiometer. We'll also display the values on an LCD. This experiment helps you understand how to use ADC and PWM components in PSoC Creator.
PSoC schematic diagram
The changing speed and brightness of blinking LED project needs the following parts:
CY8CKIT-050 PSoC 5LP Development Kit
USB Cable
Potentiometer
LED
Character LCD Display
Project Creation:
Open PSoC Creator.
Go to File > New > Project.
Choose the target device: PSoC5LP CY8CKIT-050 (CY8C5868AXI-LP035 chip).
Select "Empty Schematic" and name the project Full_LED.
Hardware Configuration:
Go to the Component Catalog on the right side of the screen, search for the following components and drag them to the TopDesign schematic:
PWM
SAR ADC
Clock
Logic Low
Digital Input Pin (three times)
Analog Pin
Digital Output Pin
Character LCD
Interrupt (twice)
Component Configuration:
Double-click on the Analog Input Pin, rename it to "Potar", and choose High Impedance Analog drive mode.
Double-click on a Digital Input Pin, rename it to "SpeedSW2", and choose Resistive Pull Up drive mode. Uncheck HW connection and set Interrupt mode to Falling edge.
Double-click on another Digital Input Pin, rename it to "BrightSW3", and choose Resistive Pull Up drive mode. Uncheck HW connection and set Interrupt mode to Falling edge.
Double-click on the remaining Digital Input Pin, rename it to "Reset", and choose Pull Up drive mode. Uncheck HW connection.
Double-click on the Digital Output Pin, rename it to "LED", choose Strong Drive mode, and set the initial drive state to Low.
Double-click on the ADC component, rename it to "ADC", set the resolution to 8 bits, the conversion rate to 100000, the input range to Vssa to Vdda (Single Ended), and choose internal Vref as the reference source.
Double-click on the PWM component, rename it to "PWM", and set PWM mode to one output.
Double-click on the Clock component and set the frequency to 100 Hz with ±5% tolerance.
Double-click on the LCD component and set it up as a 2x16 character display.
In the workspace explorer, double-click on Pins under Full_LED.cydwr and set Port to:
P6[3] for LED
P6[5] for Potar
P2[6:0] for the LCD
Appropriate ports for SpeedSW2, BrightSW3, and Reset.
Rename the interrupt components to "Speed_Int" and "Bright_Int".
Programming and Results:
Double-click on main.c in the workspace explorer under source files.
Add the following code to control the speed and brightness of the blinking LED:
Build the design by clicking on "Build" or pressing Shift+F6.
Verify and resolve any warnings or errors.
Connect the PSoC 5LP to your computer using the USB cable.
Click on "Program" or press Ctrl+F5 to upload the code to the PSoC.
Adjust the potentiometer to see the changes in the LED's speed and brightness and display the values on the LCD.
Code for main.c
PSoC real-life implementation