Playing with Arduino LEDs

I have previously played with Arduino projects, today I decided to play around with some LEDs and re-familiarise myself with the platform.

Setting up the board

As it has been a while since I last played with an Arduino, I had to reinstall the software. This is as simple as the following from the official Arduino site:

  1. Heading over to the instructions page,
  2. Downloading and installing the software,
  3. Loading up the ‘Blink’ example (the hardware equivalent of ‘Hello World!’),
  4. Configuring the board type
  5. Ensuring the correct port is selected and
  6. Testing the program.

Pulsing LEDs

I’ve been asked by a friend to help out with lighting up a future cosplay of hers so I connected up a few LEDs to get a feel for what kind of effects that were possible and what she was after.

Starting with this great SparkFun link, turns out using PWM to pulse and LED is super simple so I quickly expanded to use 4 LEDs fading at equal intervals:

const int LED1 = 11;
const int LED2 = 10;
const int LED3 = 9;
const int LED4 = 6;

void setup()
{
}

void loop()
{
  float in, out;
  
  for (in = 0; in < 6.283; in = in + 0.001)
  {
    out = cos(in) * 127.5 + 127.5;
    analogWrite(LED1,out);
    out = cos(in+1.5708) * 127.5 + 127.5;
    analogWrite(LED2,out);
    out = cos(in+3.1415) * 127.5 + 127.5;
    analogWrite(LED3,out);
    out = cos(in+4.7124) * 127.5 + 127.5;
    analogWrite(LED4,out);
  }
}

About Me

Engineer, maker, do-er...
I basically just like to make things.

Archives