Instructables

Web Controlled Arduino LED

Featured

Step 3: Uploading the Arduino LED test

Picture of Uploading the Arduino LED test
4343343184_56d82801a1.jpg
4342607203_ba222fac2e.jpg
To test the LED you can upload the following sketch to your Arduino. Reset the Arduino and make sure the colors show up in the exact same sequence as described in the code comments of the loop statement below. If you use the SparkFun LED uncomment the corresponding lines of code and delete the three analogWrites of the Ladyada LED. If the colors show up in another sequence you might have swapped some pins.

// HelloLed.pde

int redPin = 6;
int greenPin = 5;
int bluePin = 3;

void setColor (int red, int green, int blue) {
  // SparkFun LED: write value for each color
  //analogWrite(redPin, red);
  //analogWrite(greenPin, green);
  //analogWrite(bluePin, blue);

  // Ladyada LED: write inverted value for each color
  analogWrite(redPin, 255 - red);
  analogWrite(greenPin, 255 - green);
  analogWrite(bluePin, 255 - blue);

  delay(1000);
}

void setup () {
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);
}

void loop () {
  setColor(0, 0, 0); // Off
  setColor(255, 0, 0); // Red
  setColor(0, 255, 0); // Green
  setColor(0, 0, 255); // Blue
  setColor(0, 255, 255); // Aqua
  setColor(255, 255, 0); // Yellow
  setColor(255, 0, 255); // Fuchsia
  setColor(255, 255, 255); // White
}

 
Remove these adsRemove these ads by Signing Up
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!