Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Neopixel LED colour control via potentiometer
// 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();
}
}
}
@DanielLess63
Copy link

DanielLess63 commented Dec 18, 2019

i am reeiving that code : 'switchPin' was not declared in this scope, and cannot find the error

@ismailuddin
Copy link
Author

ismailuddin commented Dec 18, 2019

i am reeiving that code : 'switchPin' was not declared in this scope, and cannot find the error

Hmm, there was actually no need for that line. I've removed that line, since it was referring to a variable that wasn't declared anyways and wasn't being used anywhere in the code. Give it a shot now and it should work!

@DanielLess63
Copy link

DanielLess63 commented Dec 18, 2019

Thank , it is what i did finally, and it work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment