FEZspider: How do i code Adjustable lightintensity on MulticolorLED

Hi Guys,

im having a bit trouble about how to adjust the light intensity on my multicolorLED.
Its the FEZ spider kit im using, and im programming in VS10 C#.

I want to be able to could Press a button that can turn up the light intensity from 0-255 with around 10% adjustment pr. click on the button.

Does any of you have some good code examples, for some inspiration?

I recently did this with an Atmel AVR and you have to use PWM.

In your code below, does ts and ts2 adjust their values to give you a PWM output?

Just toggling on and off, even at different rates won’t work. You have to vary the PWM width from zero to max and find a suitable PWM frequency where you don’t get flickering.

i am pretty sure you can set the intensity of the red, blue and green led’s so you could just get the current intensity and add to it what ever value you want then set it back to the led.
this is off the top of my head so apology if its complete BS :slight_smile:

My question is more simple like:

How should i formulate/write my “if” statement so that i can increase the light intensity from 0 - 255. ex.

1 click:
one more click
add 10 in intensity…
one more click:
add 10 in intensity.

Im quite new to C#, and not fluent in it yet :slight_smile:

Thx for the quick replies though!

Hold global values that just records the intensity value for each colour. Increment the intensity value by 10 when you get the appropriate click (in the handler for the button press; I assume you have one of those) and check if it goes out of range. Last thing in your handler, call your routine to display the intensity you have recorded.

@ SpiderCred - How would you do it in a language that you know?

int led_level=0;//global variable

button += button_event

void button_event(…)
led_level = led_level + 10;

If above does not help, I suggest going back to the getting started ebook on the support page and go though it for a start.

With the above code, you might have to add a few lines of code to make sure that the level does not exceed 255. Greater than 255 might cause an argument exception.

Thx Gus,
That was exactly what i needed!