- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello !
I freshly start with Psoc.
I have 3 LED that I would like to make blink with a single function. For example:
void blink(... x)
{
x_Write(1);
Cydelay(500);
x_Write(0);
return;
}
And then somewhere in my loop, I'd have something like :
blink(LED2);
...
The problem is that I don't know what would be the type of the argument x in the function blink. I don't know how to refer a certain LED. With arduino I can use the number of the pin in the argument, is there something like this in psoc ?
Thank for your help
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
As you wrote you have CY8CKIT-059 in the previous discussion,
I wrote one for CY8CKIT-059.
But unlike CY8CKIT-044, CY8CKIT-059 has only 1 LED,
so I connected 3 external LEDs via resistors.
Pins used are
P0[7] : LED_R
P0[6]: LED_G
P0[5]: LED_B
GND: connected to each LEDs via resistors.
schematic
pins
Tera Term log
main.c
===========
#include "project.h"
#include <stdio.h>
#include "tty_utils.h"
#if 0 /* negative logic */
#define LED_ON 0u
#define LED_OFF 1u
#else /* positive logic */
#define LED_ON 1u
#define LED_OFF 0u
#endif
#define R_MASK 0x04u
#define G_MASK 0x02u
#define B_MASK 0x01u
int r_flag = 0 ;
int g_flag = 0 ;
int b_flag = 0 ;
void init_hardware(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
tty_init() ;
splash("LED Blink Test") ;
}
void poke_leds(void)
{
if (r_flag) {
if (LED_R_Read()) {
LED_R_Write(0) ;
} else {
LED_R_Write(1) ;
}
}
if (g_flag) {
if (LED_G_Read()) {
LED_G_Write(0) ;
} else {
LED_G_Write(1) ;
}
}
if (b_flag) {
if (LED_B_Read()) {
LED_B_Write(0) ;
} else {
LED_B_Write(1) ;
}
}
}
void blink(uint8_t rgb_mode)
{
print("R: ") ;
if (rgb_mode & R_MASK) {
r_flag = 1 ; /* blink R */
print("Blinking ") ;
} else {
r_flag = 0 ; /* stop R */
LED_R_Write(LED_OFF) ;
print("Stopping ") ;
}
print("G: ") ;
if (rgb_mode & G_MASK) {
g_flag = 1 ; /* blink G */
print("Blinking ") ;
} else {
g_flag = 0 ; /* stop G */
LED_G_Write(LED_OFF) ;
print("Stopping ") ;
}
print("B: ") ;
if (rgb_mode & B_MASK) {
b_flag = 1 ; /* blink B */
print("Blinking ") ;
} else {
b_flag = 0 ; /* stop B */
LED_B_Write(LED_OFF) ;
print("Stopping ") ;
}
print("\n\r") ;
}
void do_command(char *str)
{
int mode ;
sscanf(str, "%d", &mode) ;
blink(mode) ;
}
int main(void)
{
init_hardware() ;
prompt() ;
for ( ; ; ) {
if (get_line()) {
do_command(str) ;
prompt() ;
}
poke_leds() ;
CyDelay(500) ; /* 500ms */
}
}
===========
moto