Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. #include <Adafruit_NeoPixel.h> //in order to use the neopixel library
  2.  
  3. Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, 9, NEO_GRB + NEO_KHZ800); //copied from the uber guide
  4. int potValue = A0;
  5. int slideValue = A1;
  6.  
  7. void setup() {
  8. Serial.begin(9600);
  9. strip.begin();
  10. strip.show(); //initializes to nothing
  11. }
  12.  
  13. void loop() {
  14. int potReading = analogRead(potValue); //what the input reads
  15. int slideReading = analogRead(slideValue);
  16. Serial.print(slideReading); //in order to test the functionality
  17. Serial.print(" ");
  18. Serial.println(potReading);
  19. int mappedPot = map(potReading, 0, 1023, 0, 255); //changing the 10 bit value of the potentiometer to an 8 bit output for the neopixel
  20. int INVmappedPot = map(potReading, 1023, 0, 0, 255); // opposite numbers from mapperPot since 1023 and 0 are reversed
  21. int mappedSlide = map(slideReading, 100, 1023, 0, 255);
  22. 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
  23. strip.setPixelColor(0, 0, 0, 0);
  24. strip.setPixelColor(1, 0, 0, 0);
  25. strip.setPixelColor(2, 0, 0, 0);
  26. strip.setPixelColor(3, 0, 0, 0);
  27. strip.setPixelColor(4, 0, 0, 0);
  28. strip.show();
  29. }
  30. else{
  31. 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
  32. strip.setPixelColor(1, mappedPot, mappedSlide, INVmappedPot);
  33. strip.setPixelColor(2, mappedPot, mappedSlide, INVmappedPot);
  34. strip.setPixelColor(3, mappedPot, mappedSlide, INVmappedPot);
  35. strip.setPixelColor(4, mappedPot, mappedSlide, INVmappedPot);
  36. strip.show();
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement