LEDs-PSoC 6

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

cross mob
lock attach
Attachments are accessible only for community members.
aliissa02
Level 4
Level 4
100 sign-ins 50 replies posted 5 likes given

Hello,

I have attached a project. The problem that I am having is that all the LEDs work at the same time when I just want one LED to light at a time. Can anyone help please?

Kind regards,

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.

aliisa,

Try this modification of your project.

It simulates a ramping ReflectometerReading variable.

It only turns on one LED at a time.

Here is the LED turn on pattern:

LED ON Reflectometer(min) Reflectometer(max)
No LEDs 0 479
LED1 480 1039
LED2 1040 1679
LED3 1680 3039
LED4 3040 4199
LED5 4200 6000

 

It takes about 3 seconds to cycles the ReflectometerReading variable from min (0) to max (6000).

Len
"Engineering is an Art. The Art of Compromise."

View solution in original post

6 Replies
lock attach
Attachments are accessible only for community members.
Rakesh_Patrudu
Moderator
Moderator
Moderator
25 solutions authored 5 likes given 50 replies posted

Hi @aliissa02 ,

I have recreated your project, as you mentioned all LEDs are working at a time. So, I added a function to make one LED to light at a time. Kindly refer to the following attachment.

Best Regards,
Rakesh

0 Likes
aliissa02
Level 4
Level 4
100 sign-ins 50 replies posted 5 likes given

Hello,

Thank you. But still having problem that I want the LED to light according to its corresponding threshold but all of them are lighting after each other. 

0 Likes
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

aliissa,

It appears from the following function that you are turning on ALL LEDs if ReflectometerReading is greater than the assigned threshold.

 

void update_LEDs(){
   reset_LEDs();
//Led will light according to the threshold
   for (int l=0; l<NUMBER_OF_PINS;l++)
    {
        if(ReflectometerReading>=threshold[l])
        {
            Cy_GPIO_SetDrivemode(led_Port[l], led_pin[l], CY_GPIO_DM_OD_DRIVESHIGH);
            Cy_GPIO_Write(led_Port[l], led_pin[l],1); // this is to turn on the led.
	    }
    }
}

 

 

 Based on your static variable ReflectometerReading = 1100 LED P10.4 would get turned on for 50% duty cycle because of the threshold[0] = 480.  P10.6 would get turned on for 50% duty cycle because of the threshold[0] = 1050. 

Is this your intent?

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

aliissa,

Here's another issue:

The following code has an issue that throws an exception error:

 

 

 

void scanKeys(){
    int x;
    for (int k=0; k<=NUMBER_SW_PINS; k++) {
    x= Cy_GPIO_Read(SW_Port[k], SW_pin[k]); // here x will store what is status of switch port.
}

 

 

 

The for() loop is looking for an index of k=2.   This index for SW_PIN[] does not exist.  This is because you specified k<=NUMBER_SW_PINS;  Instead use: k<NUMBER_SW_PINS;  This change will only ask for SW_PINS[0] and SW_PINS[1].

When I made this fix, the code is running and with ReflectometerReading = 1100 then P10.4 and P10.6 gets turned on (for 50% DC).

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
aliissa02
Level 4
Level 4
100 sign-ins 50 replies posted 5 likes given

Hello,

Thanks for this. It is still not working. What I want to do is to have one LED working when its corresponding threshold reached and all other LEDs should be off

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

aliisa,

Try this modification of your project.

It simulates a ramping ReflectometerReading variable.

It only turns on one LED at a time.

Here is the LED turn on pattern:

LED ON Reflectometer(min) Reflectometer(max)
No LEDs 0 479
LED1 480 1039
LED2 1040 1679
LED3 1680 3039
LED4 3040 4199
LED5 4200 6000

 

It takes about 3 seconds to cycles the ReflectometerReading variable from min (0) to max (6000).

Len
"Engineering is an Art. The Art of Compromise."