Last active
April 4, 2020 21:17
-
-
Save ismailuddin/14f276f8478962a85bfc765a7e82a363 to your computer and use it in GitHub Desktop.
Neopixel LED colour control via potentiometer
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 3 | |
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; | |
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); | |
colorVal = (reading/1024.0) * 255; | |
// Neopixel Color code | |
for (x=0; x < prevVal; x++) | |
{ | |
strip.setPixelColor(x,colorVal,0,255-colorVal); | |
strip.show(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank , it is what i did finally, and it work.