久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 5224|回復: 2
收起左側

用Adafruit_NeoPixel-1.3.4的全彩燈條 Arduino源程序

[復制鏈接]
ID:69091 發表于 2020-3-10 14:13 | 顯示全部樓層 |閱讀模式
經實物實驗60顆全部點亮。多種顯示方式。

Arduino源程序如下:
  1. /*
  2. strip.setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b);
  3. 第一個參數n是彩帶中LED的編號,最接近單片機引腳的編號為0;接下來的三個參數描述像素顏色,分別表示紅色,綠色和藍色的亮度級別,0為最暗,255是最大亮度;

  4. strip.setPixelColor(uint16_t n, uint32_t c);
  5. n是彩帶中LED的編號,顏色color是一種32位類型,將紅色,綠色和藍色值合并為一個數字,有時這樣做能提高程序的效率.通過下面的方法,可以將紅色,綠色和藍色值轉換為32位類型。
  6. uint32_t magenta = strip.Color(red, green, blue);

  7. strip.setBrightness(uint8_t);
  8. 一般只在setup()中調用,以保證在整個程序執行過程中LED顏色亮度的一致性,其實在程序中通過合適的邏輯控制各像素的亮度值可能動畫效果更好.

  9. strip.show();
  10. 該方法更新彩帶上的全部LED。一個好的習慣是先利用setPixelColor()設置好整個彩帶的顏色,然后再調用show()方法,以防止出現動畫跳躍而不平滑。
  11. */
  12. #include <Adafruit_NeoPixel.h>
  13. #ifdef __AVR__
  14. #include <avr/power.h>
  15. #endif

  16. //int pinInterrupt = 2; //接中斷信號的腳  
  17.   
  18. //void onChange()  
  19. //{  
  20. //   if ( digitalRead(pinInterrupt) == LOW )  
  21. //      Serial.println("Key Down");  
  22. //   else  
  23. //      Serial.println("Key UP");  
  24. //}

  25. /******************************************key
  26. #define BUTTON 3
  27. int val=0;
  28. int old_val=0;
  29. int state=0;
  30. ****************************************/
  31. #define PIN 6

  32. // Parameter 1 = number of pixels in strip
  33. // Parameter 2 = Arduino pin number (most are valid)
  34. // Parameter 3 = pixel type flags, add together as needed:參數 3 = 像素類型標志,根據需要添加在一起:
  35. //   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
  36. //   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
  37. //   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
  38. //   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
  39. //   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)

  40. Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);

  41. // IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
  42. // pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
  43. // and minimize distance between Arduino and first pixel.  Avoid connecting
  44. // on a live circuit...if you must, connect GND first.
  45. // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
  46. void setup()
  47. {

  48.   
  49.   #if defined (__AVR_ATtiny85__)
  50.     if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
  51.   #endif
  52.   // End of trinket special code

  53. // Serial.begin(9600); //打開串口   
  54. //   pinMode( pinInterrupt, INPUT);//設置管腳為輸入  
  55. //Enable中斷管腳, 中斷服務程序為onChange(), 監視引腳變化  
  56. //attachInterrupt( digitalPinToInterrupt(pinInterrupt), onChange, CHANGE);  



  57. // pinMode(BUTTON,INPUT);//key
  58.   strip.begin();
  59.   strip.show(); // Initialize all pixels to 'off'
  60. }

  61. void loop()
  62. {
  63. /****************************************** key
  64. val = digitalRead(BUTTON);

  65.   if((val==HIGH)&&(old_val==LOW))
  66.   {
  67.     state=1-state;
  68.     delay(10);
  69.   }

  70.   old_val = val;

  71.   if(state==1)
  72.   {
  73. ********************************************/   
  74.   // Some example procedures showing how to display to the pixels:顯示如何顯示到像素的一些示例過程:
  75.   colorWipe(strip.Color(255, 0, 0), 50); // Red delay50
  76.   colorWipe(strip.Color(0, 255, 0), 50); // Green
  77.   colorWipe(strip.Color(0, 0, 225), 50); // Blue
  78.   colorWipe(strip.Color(255, 0, 255), 50); // purple
  79.   
  80.   colorWipe(strip.Color(128, 0, 175), 50); // purple
  81.   colorWipe(strip.Color(0, 128, 255), 50);
  82.   colorWipe(strip.Color(0, 255, 255), 50);
  83.   //colorWipe(strip.Color(0, 0, 0, 255), 50); // White RGBW
  84.   

  85.   
  86.   // Send a theater pixel chase in...發送劇院像素追逐.
  87.   theaterChase(strip.Color(127, 127, 127), 50); // White
  88.   theaterChase(strip.Color(255, 0, 0), 50); // Red
  89.   theaterChase(strip.Color(0, 0, 255), 50); // Blue劇院追逐
  90.   theaterChase(strip.Color(0, 255, 0), 50);
  91.   theaterChase(strip.Color(255, 0, 255), 50);
  92.   theaterChase(strip.Color(255, 255, 0), 50);
  93.   theaterChase(strip.Color(0, 255, 255), 50);
  94.   
  95.   
  96.   rainbow(20);
  97.   rainbowCycle(20);
  98.   theaterChaseRainbow(50);

  99.   rainbowCycle1(20);
  100.   rainbowCycle2(20);
  101. /************************************************** key
  102.   }
  103.   else
  104.   {
  105.     colorWipe(strip.Color(0, 255, 0), 50);
  106.   }
  107. ***************************************************/
  108. }
  109.    
  110. // Fill the dots one after the other with a color用顏色一個接一個地填充這些點
  111. void colorWipe(uint32_t c, uint8_t wait)
  112. {
  113.   for(uint16_t i=0; i<strip.numPixels(); i++)
  114.   {
  115.     strip.setPixelColor(i, c);
  116.     strip.show();
  117.     delay(wait);
  118.   }
  119. }

  120. void rainbow(uint8_t wait)
  121. {
  122.   uint16_t i, j;

  123.   for(j=0; j<256; j++)
  124.   {
  125.     for(i=0; i<strip.numPixels(); i++)
  126.     {
  127.       strip.setPixelColor(i, Wheel((i+j) & 255));
  128.     }
  129.     strip.show();
  130.     delay(wait);
  131.   }
  132. }

  133. // Slightly different, this makes the rainbow equally distributed throughout略有不同,這使得彩虹在整個
  134. void rainbowCycle(uint8_t wait)
  135. {
  136.   uint16_t i, j;

  137.   for(j=0; j<256*5; j++) // 5 cycles of all colors on wheel
  138.   {
  139.     for(i=0; i< strip.numPixels(); i++)
  140.     {
  141.       strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
  142.     }
  143.     strip.show();
  144.     delay(wait);
  145.   }
  146. }

  147. void rainbowCycle1(uint8_t wait)
  148. {
  149.   uint16_t i, j;

  150.   for(j=256*5; j>=0; j--) // 5 cycles of all colors on wheel
  151.   {
  152.     for(i=0; i< strip.numPixels(); i++)
  153.     {
  154.       strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
  155.     }
  156.     strip.show();
  157.     delay(wait);
  158.   }
  159. }

  160. void rainbowCycle2(uint8_t wait)
  161. {
  162.   uint16_t i, j;

  163.   for(j=256*5; j>=0; j--) // 5 cycles of all colors on wheel
  164.   {
  165.     for(i=strip.numPixels(); i>=0; i--)
  166.     {
  167.       strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
  168.     }
  169.     strip.show();
  170.     delay(wait);
  171.   }
  172. }
  173. //Theatre-style crawling lights.
  174. void theaterChase(uint32_t c, uint8_t wait)
  175. {
  176.   for (int j=0; j<10; j++)
  177.   {  //do 10 cycles of chasing
  178.     for (int q=0; q < 3; q++)
  179.     {
  180.       for (uint16_t i=0; i < strip.numPixels(); i=i+3)
  181.       {
  182.         strip.setPixelColor(i+q, c);    //turn every third pixel on
  183.       }
  184.       strip.show();

  185.       delay(wait);

  186.       for (uint16_t i=0; i < strip.numPixels(); i=i+3)
  187.       {
  188.         strip.setPixelColor(i+q, 0);        //turn every third pixel off
  189.       }
  190.     }
  191.   }
  192. }

  193. //Theatre-style crawling lights with rainbow effect彩虹色效果的劇院風格爬行燈
  194. void theaterChaseRainbow(uint8_t wait)
  195. {
  196.   for (int j=0; j < 256; j++)
  197.   {     // cycle all 256 colors in the wheel
  198.     for (int q=0; q < 3; q++)
  199.     {
  200.       for (uint16_t i=0; i < strip.numPixels(); i=i+3)
  201.       {
  202.         strip.setPixelColor(i+q, Wheel( (i+j) % 255));    //turn every third pixel on
  203.       }
  204.       strip.show();

  205.       delay(wait);

  206.       for (uint16_t i=0; i < strip.numPixels(); i=i+3)
  207.       {
  208.         strip.setPixelColor(i+q, 0);        //turn every third pixel off
  209.       }
  210.     }
  211.   }
  212. }

  213. // Input a value 0 to 255 to get a color value.
  214. // The colours are a transition r - g - b - back to r.
  215. uint32_t Wheel(byte WheelPos)
  216. {
  217.   WheelPos = 255 - WheelPos;
  218.   if(WheelPos < 85)
  219.   {
  220.     return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  221.   }
  222.     if(WheelPos < 170)
  223.   {
  224.     WheelPos -= 85;
  225.     return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  226.   }
  227.   WheelPos -= 170;
  228.   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  229. }
復制代碼

所有資料51hei提供下載:
sketch_RGB.rar (2.96 KB, 下載次數: 37)

評分

參與人數 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

回復

使用道具 舉報

ID:641718 發表于 2021-12-18 13:42 | 顯示全部樓層
為什么要回復需要審核,請等待通過
回復

使用道具 舉報

ID:455526 發表于 2022-2-12 13:11 | 顯示全部樓層
資源不好用
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 亚洲精品视频免费观看 | 视频一区中文字幕 | 国产精品一区三区 | 麻豆国产精品777777在线 | 在线免费观看欧美 | 免费在线h视频 | 久久久久久久av | 久久久久久久久中文字幕 | 男人天堂手机在线视频 | 成人在线一级片 | av电影一区二区 | 欧美三级在线 | 特黄级国产片 | 欧美在线一区二区三区 | 中文字幕一区二区三区四区五区 | 作爱视频免费观看 | 欧美男人亚洲天堂 | 日本中文字幕在线观看 | 国产福利在线播放麻豆 | 色女人天堂 | 国产精品美女久久久久久久久久久 | 日本三级做a全过程在线观看 | 精品欧美乱码久久久久久 | 日韩av成人| 国产精品综合色区在线观看 | 羞羞视频免费观 | 欧美一级片在线观看 | 午夜在线视频一区二区三区 | 国产乱肥老妇国产一区二 | 天天操夜夜操免费视频 | 成人一区二 | 国产精品区一区二区三区 | 亚洲精品一区二 | zzzwww在线看片免费 | 成人av电影天堂 | 四虎影院免费在线 | 精品视频一区二区三区在线观看 | 久久成人在线视频 | 精品国产黄a∨片高清在线 www.一级片 国产欧美日韩综合精品一区二区 | 国产美女在线观看 | 精品美女久久久久久免费 |