Advertisement
Guest User

fucked up code for rgb strip

a guest
Feb 27th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. #include <Adafruit_NeoPixel.h>
  2.  
  3. #define PIN 6
  4.  
  5. // Parameter 1 = number of pixels in strip
  6. // Parameter 2 = pin number (most are valid)
  7. // Parameter 3 = pixel type flags, add together as needed:
  8. // NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
  9. // NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
  10. // NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
  11. // NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
  12. Adafruit_NeoPixel strip = Adafruit_NeoPixel(16, PIN, NEO_GRB + NEO_KHZ800);
  13.  
  14. int modePin = A0; //set int for mode select pot
  15. int brightPin = A1; //set int for brightness select pot
  16.  
  17.  
  18. void setup() {
  19. strip.begin();
  20. strip.setBrightness(30); //adjust brightness here
  21. strip.show(); // Initialize all pixels to 'off'
  22. }
  23.  
  24. void demo() {
  25. // Some example procedures showing how to display to the pixels:
  26. colorWipe(strip.Color(255, 0, 0), 50); // Red
  27. colorWipe(strip.Color(0, 255, 0), 50); // Green
  28. colorWipe(strip.Color(0, 0, 255), 50); // Blue
  29. rainbow(16);
  30. rainbowCycle(16);
  31. }
  32.  
  33. // Fill the dots one after the other with a color
  34. void colorWipe(uint32_t c, uint8_t wait) {
  35. for(uint16_t i=0; i<strip.numPixels(); i++) {
  36. strip.setPixelColor(i, c);
  37. strip.show();
  38. delay(wait);
  39. }
  40. }
  41.  
  42. void rainbow(uint8_t wait) {
  43. uint16_t i, j;
  44.  
  45. for(j=0; j<256; j++) {
  46. for(i=0; i<strip.numPixels(); i++) {
  47. strip.setPixelColor(i, Wheel((i+j) & 255));
  48. }
  49. strip.show();
  50. delay(wait);
  51. }
  52. }
  53.  
  54. // Slightly different, this makes the rainbow equally distributed throughout
  55. void rainbowCycle(uint8_t wait) {
  56. uint16_t i, j;
  57.  
  58. for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
  59. for(i=0; i< strip.numPixels(); i++) {
  60. strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
  61. }
  62. strip.show();
  63. delay(wait);
  64. }
  65. }
  66.  
  67. // Input a value 0 to 255 to get a color value.
  68. // The colours are a transition r - g - b - back to r.
  69. uint32_t Wheel(byte WheelPos) {
  70. if(WheelPos < 85) {
  71. return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  72. } else if(WheelPos < 170) {
  73. WheelPos -= 85;
  74. return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  75. } else {
  76. WheelPos -= 170;
  77. return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  78. }
  79. }
  80.  
  81. void Modeselect() {
  82. int moderead = analogRead(modePin);
  83. if (moderead = 0){
  84. goto demo();
  85. } if (moderead > 0, moderead < 159){
  86. goto rainbow();
  87. } if (moderead > 159) {
  88. goto rainbowCycle();
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement