Last active
November 15, 2015 10:09
-
-
Save ismailuddin/45b5fed916d51022b24c to your computer and use it in GitHub Desktop.
Neopixel Gemma
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Arduino code for Neopixel LED controller | |
// using a potentiometer and switch button | |
// (C) Ismail Uddin, 2015 | |
// www.scienceexposure.com | |
#include <Adafruit_NeoPixel.h> | |
#define PIN 0 | |
Adafruit_NeoPixel strip = Adafruit_NeoPixel(12, PIN, NEO_GRB + NEO_KHZ800); | |
int potPin = 2; | |
int val = 0; | |
int colorVal = 0; | |
int reading = 0; | |
int x; | |
int prevVal = 0; | |
int preVal = 0; | |
boolean lastBtn = LOW; | |
boolean NeopixelColor = false; | |
boolean lastButton = LOW; | |
void setup() { | |
// put your setup code here, to run once: | |
strip.begin(); | |
strip.show(); | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
reading = analogRead(potPin); | |
val = (reading/1024.0) * 13; | |
colorVal = (reading/1024.0) * 255; | |
if (NeopixelColor == false) | |
{ | |
// Neopixel LED number and colour code | |
strip.setBrightness(40); | |
if (val != prevVal) | |
{ | |
preVal = (val/13.0)*255.0; | |
for ( x = 0; x < val; x++) | |
{ | |
strip.setPixelColor(x,preVal,0,255 - preVal); | |
} | |
for (x=val; x<13; x++) | |
{ | |
strip.setPixelColor(x,0,0,0); | |
strip.show(); | |
} | |
prevVal = val; | |
} | |
else | |
{ | |
strip.show(); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment