Cycling RGB LED

Updated on 31 August 2021
dev board Adafruit Feather Bluefruit
chip nRF52
features LED
This tutorial is more than 1 year old. If the steps below do not work, then please check the latest versions and the documentations of the individual tools used.

Before starting

Dependancies

Ensure the following dependancies are downloaded and available:

Pre-requisites

Try these simpler or similar examples:

Code

Download code cycle-rgb-led.ino
int redPin = PIN_A1;
int greenPin = PIN_A2;
int bluePin = PIN_A3;

void setup() {
  Serial.begin(115200);
  while (!Serial) delay(10);

  Serial.println("Begin RGB cycling!");

  analogWrite(redPin, 0);  // RED (purple)
  analogWrite(greenPin, 255);  // GREEN (yellow)
  analogWrite(bluePin, 0);  // BLUE (cyan)

  for (int rvalue = 0; rvalue < 255; rvalue+=50) {
    for (int gvalue = 0; gvalue < 255; gvalue+=50) {
      for (int bvalue = 0; bvalue < 255; bvalue+=50) {
        analogWrite(redPin, rvalue);  // RED (purple)
        analogWrite(greenPin, gvalue);  // GREEN (yellow)
        analogWrite(bluePin, bvalue);  // BLUE (cyan)

        display(rvalue, gvalue, bvalue);
        delay(1000);
      }
    }
  }
}

void loop() { }

void display(int red, int green, int blue) {
  Serial.print(red);
  Serial.print(", ");
  Serial.print(green);
  Serial.print(", ");
  Serial.println(blue);
}

Makefile

.PHONY: lint compile upload clean

lint:
	cpplint --extensions=ino --filter=-legal/copyright *.ino

compile:
	arduino-cli compile --fqbn adafruit:nrf52:feather52832 ./

upload:
	adafruit-nrfutil dfu genpkg --dev-type 0x0052 --application ./.*.hex dfu-package.zip
	adafruit-nrfutil dfu serial --package dfu-package.zip -p /dev/tty.SLAB_USBtoUART -b 115200

clean:
	rm -f .*.bin
	rm -f .*.elf
	rm -f .*.hex
	rm -f *.zip

flash: lint compile upload clean

Schematic

Wire up the hardware accordingly

Cycling RGB LED schematic

Description

Cycle through all the colors in step of 10.