Two Blinking LEDs at different rates with the Scoop Library

Here is an example of doing two things at once on an Arduino Uno.

The red LED is blinking fast and the yellow LED is blinking at a slower rate. Each blinking operation is a separate task with its own loop() function. Each loop calculates a sine function which is applied to an analog output pin of the LED.

For this simple example, you could easily do this inside the main arduino loop() function. However, the projects get a little bigger, having separate tasks makes things a lot simpler to manage,

Here’s the interesting part of the source. It’s based on a Scoop template created by Fabrice Oudert.

// First Task - Fast Red LED
struct task1 :
SCoopTask<task1> {
static void setup() {}
static void loop() {
  for (int x=0; x<180; x++) {
    float sinVal = (sin(radians(x)));
    int ledVal = int(sinVal*255);
    analogWrite(redLedPin, ledVal);
    sleep(2); // this sleep defines the sine frequency
  sleep(10); // this sleep add a down time between sines
} task1;

The complete source code is in my bitbucket under BlinkingLedsScoopTest.

I will post the Fritzing schematic a little later…

Glitch Art with Arduino and LED strip.

I’m working on driving LEDs strip from an Arduino Uno. I setup a small circuit around a TIP 121 and a photo resistor inspired from this post on Dimming a 12V LED Strip With an Arduino.

We the photo resistor input gets too low, I unintentionally send -1 on the pin which is probably interpreted as HIGH and the LED strip flashes. See the video:

I love glitch art.