Skip to content

Instantly share code, notes, and snippets.

@grahamplata
Last active April 30, 2019 01:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grahamplata/a34ea1c66a88c8b31dbf07fd695af6dd to your computer and use it in GitHub Desktop.
Save grahamplata/a34ea1c66a88c8b31dbf07fd695af6dd to your computer and use it in GitHub Desktop.
potentiometer and neopixel exploration
#include <Adafruit_NeoPixel.h>
// constants
#define PIN 1
#define NUMPIXELS 12
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB);
// define colors
uint32_t red = strip.Color(255, 0, 0);
uint32_t orange = strip.Color(255, 50, 0);
uint32_t yellow = strip.Color(255, 255, 0);
uint32_t yellowgreen = strip.Color(210, 255, 0);
uint32_t green = strip.Color(0, 255, 0);
// utility variables
uint8_t mode = 1;
int sensorPin = 1;
int outputValue = 0;
void setup() {
strip.begin();
strip.show();
strip.setBrightness(40);
}
void loop() {
int i;
// mapping analog value
outputValue = map(analogRead(sensorPin), 0, 1023, 0, 12);
// set color neopixel values
for (i = 0; i < outputValue; i++) {
if (i < 6) {
strip.setPixelColor(i, green);
} else if (i == 6) {
strip.setPixelColor(i, yellowgreen);
} else if (i > 6 && i < 9) {
strip.setPixelColor(i, yellow);
} else if (i == 9) {
strip.setPixelColor(i, orange);
} else {
strip.setPixelColor(i, red);
}
}
// clear pixel values
for (i = outputValue; i < NUMPIXELS; i++) {
strip.setPixelColor(i, 0, 0, 0);
}
// show your work
strip.show();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment