Guest User

Arduino blinkry

a guest
Aug 24th, 2016
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.06 KB | None | 0 0
  1. #include <Adafruit_NeoPixel.h>
  2.  
  3.  
  4.  
  5. ////// NASTAVENI LEVEHO PASKU
  6. #define PIN_L_PASEK pin l pasku
  7. #define NUM_LEDS_L_PASEK pocet led l pasku
  8. Adafruit_NeoPixel l_pasek = Adafruit_NeoPixel(NUM_LEDS_L, PIN_L_PASEK, NEO_GRB + NEO_KHZ800);
  9.  
  10. ////// NASTAVENI PRAVEHO PASKU
  11. #define PIN_P_PASEK pin p pasku
  12. #define NUM_LEDS_P_PASEK pocet led p pasku
  13. Adafruit_NeoPixel p_pasek = Adafruit_NeoPixel(NUM_LEDS_P, PIN_P_PASEK, NEO_GRB + NEO_KHZ800);
  14.  
  15.  
  16. ////////////POCET LED JEDNOHO Z PASKU
  17. #define NUM_LEDS NUM_LEDS_L_PASEK
  18.  
  19.  
  20. ////// NASTAVENI VSTUPNICH PINU
  21. #define L_BLINKR_PIN vstup z l blinkru
  22. #define P_BLINKR_PIN vstup z p blinkru
  23.  
  24. void setup() {
  25. /// Nastaveni pinu na ktere pujdou vstupy/ blinkry
  26.   pinMode(L_BLINKR_PIN, INPUT);
  27.   pinMode(R_BLINKR_PIN, INPUT);
  28.  
  29. ///Nastaveni pasku
  30.   l_pasek.begin();
  31.   l_pasek.show();
  32.  
  33.   p_pasek.begin();
  34.   p_pasek.show();
  35. }
  36.  
  37. void loop() {
  38.     if(digitalRead(P_BLINKR_PIN) && !digitalRead(L_BLINKR_PIN))
  39.     {
  40.       colorWipe(0xff,0xa2,0x00, 40, 1);
  41.       colorWipe(0x00,0x00,0x00, 5, 1);
  42.     }
  43.  
  44.     if(digitalRead(L_BLINKR_PIN) && !digitalRead(P_BLINKR_PIN))
  45.     {
  46.       colorWipe(0xff,0xa2,0x00, 40, 0);
  47.       colorWipe(0x00,0x00,0x00, 5, 0);
  48.     }
  49.  
  50.  
  51.      if(digitalRead(L_BLINKR_PIN) && digitalRead(P_BLINKR_PIN))
  52.     {
  53.       colorWipe(0xff,0xa2,0x00, 40, 2);
  54.       colorWipe(0x00,0x00,0x00, 5, 2);
  55.     }
  56.  
  57. }
  58.  
  59. void colorWipe(byte red, byte green, byte blue, int SpeedDelay, int pasek /// 0 = levy pasek / 1 = pravy pasek) {
  60.   if(pasek == 0){
  61.     for(uint16_t i=0; i<NUM_LEDS_L_PASEK; i++) {
  62.       setPixelL_PASEK(i, red, green, blue);
  63.       showL_PASEK();
  64.       delay(SpeedDelay);
  65.      }
  66.     }
  67.  
  68.   if(pasek == 1){
  69.      for(uint16_t i=0; i<NUM_LEDS_P_PASEK; i++) {
  70.       setPixelP_PASEK(i, red, green, blue);
  71.       showP_PASEK();
  72.       delay(SpeedDelay);
  73.      }
  74.     }
  75.  
  76.  
  77.     if(pasek == 2){
  78.     for(uint16_t i=0; i<NUM_LEDS; i++) {
  79.       setPixelL_PASEK(i, red, green, blue);
  80.       setPixelP_PASEK(i, red, green, blue);
  81.       showL_PASEK();
  82.       showP_PASEK();
  83.       delay(SpeedDelay);
  84.      }
  85.     }
  86.  
  87.  
  88. }
  89.  
  90.  
  91. void showL_PASEK() {
  92.  #ifdef ADAFRUIT_NEOPIXEL_H
  93.    // NeoPixel
  94.     l_pasek.show();
  95.  #endif
  96.  #ifndef ADAFRUIT_NEOPIXEL_H
  97.    // FastLED
  98.    FastLED.show();
  99.  #endif
  100. }
  101.  
  102. void setPixel_L_PASEK(int Pixel, byte red, byte green, byte blue) {
  103.  #ifdef ADAFRUIT_NEOPIXEL_H
  104.    // NeoPixel
  105.    l_pasek.setPixelColor(Pixel, l_pasek.Color(red, green, blue));
  106.  #endif
  107.  #ifndef ADAFRUIT_NEOPIXEL_H
  108.    // FastLED
  109.    leds[Pixel].r = red;
  110.    leds[Pixel].g = green;
  111.    leds[Pixel].b = blue;
  112.  #endif
  113. }
  114.  
  115. void showP_PASEK() {
  116.  #ifdef ADAFRUIT_NEOPIXEL_H
  117.    // NeoPixel
  118.    p_pasek.show();
  119.  #endif
  120.  #ifndef ADAFRUIT_NEOPIXEL_H
  121.    // FastLED
  122.    p_pasek.show();
  123.  #endif
  124. }
  125.  
  126. void setPixel_P_PASEK(int Pixel, byte red, byte green, byte blue) {
  127.  #ifdef ADAFRUIT_NEOPIXEL_H
  128.    // NeoPixel
  129.    p_pasek.setPixelColor(Pixel, p_pasek.Color(red, green, blue));
  130.  #endif
  131.  #ifndef ADAFRUIT_NEOPIXEL_H
  132.    // FastLED
  133.    leds[Pixel].r = red;
  134.    leds[Pixel].g = green;
  135.    leds[Pixel].b = blue;
  136.  #endif
  137. }
Advertisement
Add Comment
Please, Sign In to add comment