Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "PinChangeInterrupt.h"
  2. #include <Adafruit_NeoPixel.h>
  3.  
  4. // constants won't change. They're used here to
  5. // set pin numbers:
  6.  
  7. int wait = 20;
  8.  
  9.  
  10. const int ledPin = 6;     // the number of the neopixel strip
  11. const int numLeds = 37;
  12.  
  13. int jasnosc = 50;
  14. bool tryb;
  15.  
  16. //Adafruit_NeoPixel pixels = Adafruit_NeoPixel(8, ledPin);
  17. Adafruit_NeoPixel strip = Adafruit_NeoPixel(numLeds, ledPin, NEO_GRB + NEO_KHZ800);
  18.  
  19. #define gora 12
  20. #define menu 11
  21. #define dol 10
  22.  
  23.  
  24.  
  25. void setup() {
  26.   Serial.begin(9600);
  27.   pinMode(12, INPUT_PULLUP); //gora
  28.   pinMode(11, INPUT_PULLUP); //menu
  29.   pinMode(10, INPUT_PULLUP); //dol
  30.   strip.begin();
  31.   strip.setBrightness(50);
  32.  
  33.   attachPCINT(digitalPinToPCINT(gora), goraf, FALLING);
  34.   attachPCINT(digitalPinToPCINT(menu), menuf, FALLING);
  35.   attachPCINT(digitalPinToPCINT(dol), dolf, FALLING);
  36.  
  37. }
  38.  
  39. void goraf(){
  40. if(jasnosc<250){
  41.  jasnosc=jasnosc+10;
  42.   }
  43.   Serial.print("gora   ");
  44.   strip.setBrightness(jasnosc);
  45.   Serial.println(jasnosc, DEC);
  46. }
  47.  
  48. void menuf(){
  49.   Serial.println("menu");
  50.   Serial.print(tryb);
  51.   tryb = !tryb;
  52.   wait = 0;
  53.  
  54. }
  55.  
  56. void dolf(){
  57. if(jasnosc>0){
  58.  jasnosc=jasnosc-10;
  59.   }
  60.     Serial.print("dol   ");
  61.     strip.setBrightness(jasnosc);
  62.   Serial.println(jasnosc, DEC);
  63. }
  64.  
  65. uint32_t Wheel(byte WheelPos) {
  66.   if(WheelPos < 85) {
  67.     return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  68.   }
  69.   else if(WheelPos < 170) {
  70.     WheelPos -= 85;
  71.     return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  72.   }
  73.   else {
  74.     WheelPos -= 170;
  75.     return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  76.   }
  77. }
  78.  
  79.  
  80.  
  81.  
  82. void loop() {
  83.  
  84. if(tryb){
  85.   strip.setBrightness(jasnosc);
  86.   Serial.println("tryb rgb");
  87.   wait = 20;
  88.   rainbow();
  89.  
  90. }
  91.  
  92. else
  93. {
  94.    int i;  
  95.   for(i=0; i < numLeds; i++ ) {
  96.     strip.setBrightness(jasnosc);
  97.       strip.setPixelColor(i,255,255,255);
  98.      
  99.     }
  100.     strip.show();
  101.  
  102. }
  103.  
  104. strip.show();
  105. }
  106.  
  107. void rainbow() {
  108.   uint16_t i, j;
  109.  
  110.   for(j=0; j<256; j++) {
  111.     for(i=0; i<strip.numPixels(); i++) {
  112.       strip.setBrightness(jasnosc);
  113.       strip.setPixelColor(i, Wheel((i*1+j) & 255));
  114.     }
  115.     strip.show();
  116.     delay(wait);
  117.   }
  118. }
  119.  
  120.  
  121. // Input a value 0 to 255 to get a color value.
  122. // The colours are a transition r - g - b - back to r.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement