thotcon 0x8 badge RGB demo
// RGB demo on the Thotcon 0x8 badge | |
// Board type: Arduino Leonardo | |
#include "FastLED.h" | |
#define NUM_LEDS 4 | |
#define DATA_PIN 11 | |
// Define the array of leds | |
CRGB leds[NUM_LEDS]; | |
const int analog0 = A0; // Analog input pin that the potentiometer is attached to | |
const int analog1 = A1; | |
const int analog2 = A2; | |
int sensorValue0 = 0; | |
int sensorValue1 = 0; | |
int sensorValue2 = 0; | |
int red = 0; | |
int green = 0; | |
int blue = 0; | |
void setup() { | |
//Serial.begin(9600); | |
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS); | |
} | |
void loop() { | |
// read the analog in value: | |
sensorValue0 = analogRead(analog0); | |
sensorValue1 = analogRead(analog1); | |
sensorValue2 = analogRead(analog2); | |
// print the results to the serial monitor: | |
// Serial.print("A0 = "); | |
// Serial.println(sensorValue0); | |
// Serial.print("A1 = "); | |
// Serial.println(sensorValue1); | |
// Serial.print("A2 = "); | |
// Serial.println(sensorValue2); | |
// Map the 0 to 1023 value from the pots to 255 to 0 brightness for the LEDs | |
red = map(sensorValue2, 0, 1023, 255, 0); | |
green = map(sensorValue1, 0, 1023, 255, 0); | |
blue = map(sensorValue0, 0, 1023, 255, 0); | |
// Sets the first 3 LEDs to Red, Green, and Blue individual brightness levels | |
leds[0].r = red; | |
leds[1].g = green; | |
leds[2].b = blue; | |
// Combines the 3 color brightness levels and displays them all mixed on the 4th LED | |
leds[3] = CRGB( red, green, blue ); | |
FastLED.show(); | |
// wait 2 milliseconds before the next loop | |
// for the analog-to-digital converter to settle | |
// after the last reading: | |
delay(2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment