CYW94343WWCD1_EVB dimming LED

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

cross mob
alorc_4110946
Level 1
Level 1
First like received

We are usingCYW94343WWCD1_EVB. Ran thru the exercise with the help of support.

We have been using button, intercept, pwm programs, number times LED pressed using CYW94343WWCD1_EVB. Looking at the code it uses high and low to control the LED.


Able to see the use of “high” and “low” to turn off and on the LED. Also, the PWM scenario was verified.

Like to have board controlled by the button to Start  LED low ( off), than press button for 25% brightness, press button again for 50%, press again for 75%, press again than again for high (fully on). Then start the cycle again.

Question:

Seeing where or how one can get percentages of “high”

thank

aao

0 Likes
1 Solution
RaktimR_11
Moderator
Moderator
Moderator
500 replies posted 250 replies posted 100 replies posted

You can set up a button interrupt in the main application code. In the ISR, you can modify a button_press counter to record the number of times the button is pressed. Based on the counter value, you can set up a switch case or conditional blocks to modify the duty cycle of PWM. If you want the process to be infinite, you can set the counter as a ring counter otherwise a simple step-up counter should be fine. I have just added a very basic code to demonstrate your use-case

#include "wiced.h"

// Use one of the following defines depending on if you are using the shield board

//#define PWM_PIN WICED_PWM_2 // For shield board Rev 1*

#define PWM_PIN WICED_PWM_1 // For shield board Rev 2.*

//#define PWM_PIN WICED_PWM_4 // For base board red LED. Also need to change PWM_4 mux in platform.c from PIN_GPIO_15 to PIN_PWM_3

uint8_t flag = 0;

float duty_cycle = 0.0;

void button_isr(void* arg)

{

    flag += 1;

    switch (flag)

    {

    case 1:

    {

        WPRINT_APP_INFO(("Value of flag is %d\n",flag));

                    duty_cycle = 25.0;

                    wiced_pwm_init(PWM_PIN, 1000, duty_cycle);

                    wiced_pwm_start(PWM_PIN);

                    wiced_rtos_delay_milliseconds(10);

                    break;

    }

    case 2:

    {

        WPRINT_APP_INFO(("Value of flag is %d\n",flag));

                    duty_cycle = 50.0;

                    wiced_pwm_init(PWM_PIN, 1000, duty_cycle);

                    wiced_pwm_start(PWM_PIN);

                    wiced_rtos_delay_milliseconds(10);

                    break;

    }

    case 3:

    {

        WPRINT_APP_INFO(("Value of flag is %d\n",flag));

                    duty_cycle = 75.0;

                    wiced_pwm_init(PWM_PIN, 1000, duty_cycle);

                    wiced_pwm_start(PWM_PIN);

                    wiced_rtos_delay_milliseconds(10);

                    break;

    }

    case 4:

    {

        WPRINT_APP_INFO(("Value of flag is %d\n",flag));

                    duty_cycle = 0.0;

                    flag = 0;

                    wiced_pwm_init(PWM_PIN, 1000, duty_cycle);

                    wiced_pwm_start(PWM_PIN);

                    wiced_rtos_delay_milliseconds(10);

                    break;

    }

    default:

    {

        WPRINT_APP_INFO(("One cycle completed\n"));

    }

    }

}

void application_start( )

{

    wiced_init();   /* Initialize the WICED device */

    wiced_gpio_deinit(WICED_LED2);

    wiced_gpio_deinit(WICED_LED1);

    wiced_gpio_input_irq_enable(WICED_BUTTON1, IRQ_TRIGGER_FALLING_EDGE, button_isr , NULL);

}

View solution in original post

2 Replies
RaktimR_11
Moderator
Moderator
Moderator
500 replies posted 250 replies posted 100 replies posted

You can set up a button interrupt in the main application code. In the ISR, you can modify a button_press counter to record the number of times the button is pressed. Based on the counter value, you can set up a switch case or conditional blocks to modify the duty cycle of PWM. If you want the process to be infinite, you can set the counter as a ring counter otherwise a simple step-up counter should be fine. I have just added a very basic code to demonstrate your use-case

#include "wiced.h"

// Use one of the following defines depending on if you are using the shield board

//#define PWM_PIN WICED_PWM_2 // For shield board Rev 1*

#define PWM_PIN WICED_PWM_1 // For shield board Rev 2.*

//#define PWM_PIN WICED_PWM_4 // For base board red LED. Also need to change PWM_4 mux in platform.c from PIN_GPIO_15 to PIN_PWM_3

uint8_t flag = 0;

float duty_cycle = 0.0;

void button_isr(void* arg)

{

    flag += 1;

    switch (flag)

    {

    case 1:

    {

        WPRINT_APP_INFO(("Value of flag is %d\n",flag));

                    duty_cycle = 25.0;

                    wiced_pwm_init(PWM_PIN, 1000, duty_cycle);

                    wiced_pwm_start(PWM_PIN);

                    wiced_rtos_delay_milliseconds(10);

                    break;

    }

    case 2:

    {

        WPRINT_APP_INFO(("Value of flag is %d\n",flag));

                    duty_cycle = 50.0;

                    wiced_pwm_init(PWM_PIN, 1000, duty_cycle);

                    wiced_pwm_start(PWM_PIN);

                    wiced_rtos_delay_milliseconds(10);

                    break;

    }

    case 3:

    {

        WPRINT_APP_INFO(("Value of flag is %d\n",flag));

                    duty_cycle = 75.0;

                    wiced_pwm_init(PWM_PIN, 1000, duty_cycle);

                    wiced_pwm_start(PWM_PIN);

                    wiced_rtos_delay_milliseconds(10);

                    break;

    }

    case 4:

    {

        WPRINT_APP_INFO(("Value of flag is %d\n",flag));

                    duty_cycle = 0.0;

                    flag = 0;

                    wiced_pwm_init(PWM_PIN, 1000, duty_cycle);

                    wiced_pwm_start(PWM_PIN);

                    wiced_rtos_delay_milliseconds(10);

                    break;

    }

    default:

    {

        WPRINT_APP_INFO(("One cycle completed\n"));

    }

    }

}

void application_start( )

{

    wiced_init();   /* Initialize the WICED device */

    wiced_gpio_deinit(WICED_LED2);

    wiced_gpio_deinit(WICED_LED1);

    wiced_gpio_input_irq_enable(WICED_BUTTON1, IRQ_TRIGGER_FALLING_EDGE, button_isr , NULL);

}

It worked. can close "CASE". Thank you.

0 Likes