Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Adafruit_NeoPixel.h> //in order to use the neopixel library
- Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, 9, NEO_GRB + NEO_KHZ800); //copied from the uber guide
- int potValue = A0;
- int slideValue = A1;
- void setup() {
- Serial.begin(9600);
- strip.begin();
- strip.show(); //initializes to nothing
- }
- void loop() {
- int potReading = analogRead(potValue); //what the input reads
- int slideReading = analogRead(slideValue);
- Serial.print(slideReading); //in order to test the functionality
- Serial.print(" ");
- Serial.println(potReading);
- int mappedPot = map(potReading, 0, 1023, 0, 255); //changing the 10 bit value of the potentiometer to an 8 bit output for the neopixel
- int INVmappedPot = map(potReading, 1023, 0, 0, 255); // opposite numbers from mapperPot since 1023 and 0 are reversed
- int mappedSlide = map(slideReading, 100, 1023, 0, 255);
- if (slideReading < 100){ //if the dimmer is slide down, the neopixel will turn off. The print serial monitor showed that this potentiometer didn't quite reach 0 consistently when all the way off
- strip.setPixelColor(0, 0, 0, 0);
- strip.setPixelColor(1, 0, 0, 0);
- strip.setPixelColor(2, 0, 0, 0);
- strip.setPixelColor(3, 0, 0, 0);
- strip.setPixelColor(4, 0, 0, 0);
- strip.show();
- }
- else{
- strip.setPixelColor(0, mappedPot, mappedSlide, INVmappedPot); //r g b are mapped by different values. With the dimmer and rotator combined, a whole color spectrum can be obtained
- strip.setPixelColor(1, mappedPot, mappedSlide, INVmappedPot);
- strip.setPixelColor(2, mappedPot, mappedSlide, INVmappedPot);
- strip.setPixelColor(3, mappedPot, mappedSlide, INVmappedPot);
- strip.setPixelColor(4, mappedPot, mappedSlide, INVmappedPot);
- strip.show();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement