{"id":10650,"date":"2022-11-08T09:51:35","date_gmt":"2022-11-08T01:51:35","guid":{"rendered":"http:\/\/www.szryc.com\/?p=10650"},"modified":"2022-11-08T09:51:35","modified_gmt":"2022-11-08T01:51:35","slug":"%e9%80%82%e5%90%88%e5%85%a5%e9%97%a8%e7%9a%84led%e7%9f%a9%e9%98%b5%e9%a9%b1%e5%8a%a8%e8%ae%be%e8%ae%a1","status":"publish","type":"post","link":"http:\/\/www.szryc.com\/?p=10650","title":{"rendered":"\u9002\u5408\u5165\u95e8\u7684LED\u77e9\u9635\u9a71\u52a8\u8bbe\u8ba1"},"content":{"rendered":"

\u4e00\u4e2a\u5b8c\u5168\u4ece\u5934\u5f00\u59cb\u5236\u4f5c\u7684\u81ea\u5b9a\u4e49\u77e9\u9635\u5236\u4f5c\uff0c\u60f3\u8981\u73a9\u7684\u5c0f\u4f19\u4f34\u8bd5\u8bd5\u770b\u5427\u3002<\/p>\n

\u9996\u5148\u662fLED\u77e9\u9635\u7684\u5e03\u5c40\uff0c\u8be5\u77e9\u9635\u91c7\u7528 16x8 \u914d\u7f6e\uff0c\u5e76\u4ee5 OXPLOW \u5e03\u5c40\u5e03\u5c40\uff08OXPLOW \u662f\u4e00\u79cd\u77e9\u9635\u7c7b\u578b\uff0c\u5176\u4e2d LED \u5728\u4e00\u884c\u4e2d\u5355\u5411\u79fb\u52a8\uff0c\u7136\u540e\u5728\u4e0b\u4e00\u884c\u5411\u540e\u79fb\u52a8\uff0c\u4f9d\u6b64\u7c7b\u63a8\uff0c\u4e5f\u5c31\u662f\u6bcf\u4e00\u6392\u7684\u6700\u540e\u4e00\u4e2a\u90fd\u8fde\u5230\u4e0b\u4e00\u6392\u7684\u7b2c\u4e00\u4e2a\uff0c\u8fd9\u79cd\u5e03\u5c40\u4e5f\u79f0\u4e3a boustrophedon\uff09\u3002\u8fd8\u6709\u53e6\u4e00\u79cd\u5e03\u5c40\u662f\u86c7\u5f62\u5e03\u5c40\uff0cLED \u50cf\u86c7\u4e00\u6837\u4ee5\u8fde\u7eed\u7684\u94fe\u6761\u5e03\u5c40\u3002<\/p>\n

\"42c3fbfc-5ea4-11ed-8abf-dac502259ad0\"<\/div>\n

\u77e9\u9635\u901a\u8fc7FAST LED\u5e93\u63a7\u5236\uff0c\u4f46\u53ef\u4ee5\u4f7f\u7528Ad<\/u>afruit\u7684Neopixel\u5e93\u6216SmartMatrix\u5e93\u7b49\u4e00\u7cfb\u5217\u73b0\u6709\u5e93\u8fdb\u884c\u64cd\u4f5c\u3002<\/p>\n

\u6240\u9700\u6750\u6599\u6709\uff1a<\/strong>WS2812B \u53d1\u5149\u4e8c\u6781\u7ba1<\/u>\u3001\u5b9a\u5236\u7535\u8def\u677f\u3001Arduino<\/u>\u00a0Nano\u3001\u9762\u5305\u677f\u3002<\/p>\n

WS2812B\u4e0d\u964c\u751f\u5427\uff0c\u4e4b\u524d\u8fbe\u5c14\u95fb\u8bf4\u4e5f\u53d1\u8fc7\u5f88\u591aWS2812B\u7684\u9879\u76ee\u3002WS2812B\u662f\u4e00\u6b3e\u667a\u80fd\u63a7\u5236LED\u5149\u6e90\uff0c\u5c06\u63a7\u5236\u7535\u8def\u548cRGB\u82af\u7247\u96c6\u6210\u52305050\u7ec4\u4ef6\u5c01\u88c5\u4e2d\uff0c\u5185\u90e8\u5305\u62ec\u667a\u80fd\u6570\u5b57\u7aef\u53e3\u6570\u636e\u9501\u5b58\u5668\u548c\u4fe1\u53f7\u6574\u5f62\u653e\u5927\u9a71\u52a8\u7535\u8def<\/u>\u3002<\/p>\n

\u6570\u636e\u4f20\u8f93\u534f\u8bae\u4f7f\u7528\u5355 NZR \u901a\u4fe1\u6a21\u5f0f\u3002\u4e0a\u7535\u590d\u4f4d\u540e\uff0cDIN\u7aef\u53e3\u63a5\u6536\u6765\u81ea\u63a7\u5236\u5668\u7684\u6570\u636e\uff0c\u7b2c\u4e00\u4e2a\u50cf\u7d20\u6536\u96c6\u521d\u59cb24\u4f4d\u6570\u636e\u7136\u540e\u53d1\u9001\u5230\u5185\u90e8\u6570\u636e\u9501\u5b58\u5668\uff0c\u5176\u4ed6\u901a\u8fc7\u5185\u90e8\u4fe1\u53f7\u6574\u5f62\u653e\u5927\u7535\u8def\u91cd\u5851\u7684\u6570\u636e\u901a\u8fc7DO\u7aef\u53e3\u53d1\u9001\u5230\u4e0b\u4e00\u4e2a\u7ea7\u8054\u50cf\u7d20\u3002<\/p>\n

\"42ed4804-5ea4-11ed-8abf-dac502259ad0\"<\/div>\n

WS2812B\u5de5\u4f5c\u7535\u538b\u5728+3.5~+5.3V\u00a0DC<\/u>\u4e4b\u95f4\u3002<\/p>\n

\u4ece\u539f\u7406\u56fe\u5f00\u59cb\u8bbe\u8ba1\uff0c\u8be5\u539f\u7406\u56fe\u7531 128 \u4e2a RGB LED \u7ec4\u6210\uff0c\u5728 OXPLOW \u5e03\u5c40\u4e2d\u6765\u56de\u8fde\u63a5\u3002\u6709\u4e00\u4e2a CON4 \u63a5\u63d2\u4ef6\uff0c\u7528\u4e8e\u8fde\u63a5 VCC\u3001GND\u3001Din \u548c Dout \u5f15\u811a\uff0c\u4e5f\u6709\u5355\u72ec\u7684\u7528\u4e8e VCC\u3001GND \u548c Din \u7684\u4e09\u4e2a\u4e0d\u540c\u5f15\u811a\u8fde\u63a5\u3002\u6240\u6709 LED \u7684 VCC \u548c GND \u90fd\u5e76\u8054\u8fde\u63a5\u3002<\/p>\n

\u7b2c 1 \u4e2a\u7684 Dout \u8fdb\u5165\u7b2c 2 \u4e2a\u7684 Din\uff0c\u7b2c 2 \u4e2a\u7684 Dout \u8f6c\u5230\u7b2c 3 \u4e2a\u50cf\u7d20\u7684 Din\uff0c\u4e00\u76f4\u6301\u7eed\u5230\u7b2c 128 \u4e2a\u3002<\/p>\n

\"44bcda5a-5ea4-11ed-8abf-dac502259ad0\"<\/div>\n

\u6bcf\u4e2aWS2812 LED\u90fd\u9700\u8981\u4e00\u4e2a0.1uF\u7684\u7535\u5bb9\u5668<\/u>\u624d\u80fd\u6b63\u5e38\u5de5\u4f5c\uff0c\u4f46\u7531\u4e8e\u7a7a\u95f4\u6709\u9650\uff0c\u6ca1\u6709\u6dfb\u52a0\u7535\u5bb9<\/u>\u5668\u3002\u8be5\u677f\u5de5\u4f5c\u6b63\u5e38\uff0c\u4f46\u5982\u679c\u5b83\u6709\u4e00\u4e9b\u95ee\u9898\uff0c\u53ef\u4ee5\u6dfb\u52a0\u4e00\u4e2a\u5e26\u6709VCC\u548cGND\u7684\u5916\u90e8\u7535\u5bb9\u3002<\/p>\n

\u7136\u540e\u8fdb\u884cPCB<\/u>\u5236\u4f5c\u4e0e\u6253\u6837\u3001\u5668\u4ef6\u710a\u63a5\uff1a<\/p>\n

\"4522a556-5ea4-11ed-8abf-dac502259ad0\"<\/div>\n
\"4553c370-5ea4-11ed-8abf-dac502259ad0\"<\/div>\n

\u8981\u9a71\u52a8\u77e9\u9635\u677f\uff0c\u9700\u8981\u6309\u7167\u4e0b\u9762\u7684\u63a5\u7ebf\u56fe\u5c06Arduino Nano\u8fde\u63a5\u5230\u77e9\u9635\u3002<\/p>\n

\"45890fee-5ea4-11ed-8abf-dac502259ad0\"<\/div>\n

\u77e9\u9635\u7684VCC\u5c06\u8fde\u63a5\u5230Arduino\u76845V<\/p>\n

\u63a5\u5730\u5230\u63a5\u5730<\/p>\n

\u77e9\u9635\u81f3D9\u7684Din\uff08\u4efb\u4f55PWM\u5f15\u811a\uff09<\/p>\n

\u4e3a\u4e86\u4f7f\u7528\u8fd9\u4e2a\u677f\uff0c\u53ef\u4ee5\u5229\u7528\u4e00\u5806\u73b0\u6709\u7684\u5e93\uff0c\u6bd4\u5982 FASTLED \u5e93\u3002 FASTLED\u662f\u4e00\u4e2a\u7528\u4e8e\u63a7\u5236\u5404\u79cdLED\u82af\u7247\u7ec4\u7684\u5e93\uff0c\u4f8b\u5982adafruit\uff08Neopixel\uff0cDotStar\uff0cLPD8806\uff09\uff0cSparkfun\uff08WS2801\uff09\u7b49\u3002 \u8fd9\u662f\u5b83\u7684GitHub\u9875\u9762\uff0c\u9700\u8981\u5728Arduino IDE\u4e2d\u4e0b\u8f7d<\/u>\u5e76\u5b89\u88c5\u5e93\u3002https:\/\/github.com\/FastLED\/FastLED \u8fd9\u662f\u5c06\u4f7f\u7528\u7684\u4e3b\u7a0b\u5e8f\uff0c\u88ab\u79f0\u4e3aNoisePlusPalette<\/u>\uff0c\u53ef\u4ee5\u5728FASTLED\u793a\u4f8b\u4e2d\u627e\u5230\u3002<\/p>\n

#include \r\n\r\n\r\n#define LED_PI<\/u>N     9\r\n#define BRIGHTNESS  96\r\n#define LED_TYPE    WS2811\r\n#define COLOR_ORDER GRB\r\n\r\n\r\nconst uint8_t kMatrixWidth  = 16;\r\nconst uint8_t kMatrixHeight = 8;\r\nconst\u00a0bool\u00a0\u00a0\u00a0\u00a0kMatrixSerpen<\/u>TI<\/u>neLayout\u00a0=\u00a0false;\r\n\r\n\r\n#define NUM_LEDS (kMatrixWidth * kMatrixHeight)\r\n#define MAX_DIMENSION ((kMatrixWidth>kMatrixHeight) ? kMatrixWidth : kMatrixHeight)\r\n\r\n\r\n\/\/ The leds\r\nCRGB leds[kMatrixWidth * kMatrixHeight];\r\n\r\n\r\nstaTIc uint16_t x;\r\nstaTIc uint16_t y;\r\nstaTIc uint16_t z;\r\n\r\n\r\nuint16_t\u00a0speed\u00a0=\u00a020;\u00a0\/\/\u00a0speed\u00a0is\u00a0set\u00a0dynamically\u00a0once\u00a0we've\u00a0started\u00a0up\r\nuint16_t scale = 30; \/\/ scale is set dynamically once we've started up\r\n\r\n\r\nuint8_t noise[MAX_DIMENSION][MAX_DIMENSION];\r\n\r\n\r\nCRGBPalette16 currentPalette( PartyColors_p );\r\nuint8_t       colorLoop = 1;\r\n\r\n\r\nvoid setup() {\r\n  delay(3000);\r\n  LEDS.addLeds<led_type,led_pin,color_order>(leds,NUM_LEDS);\r\n  LEDS.setBrightness(BRIGHTNESS);\r\n\r\n\r\n  \/\/ Initialize our coordinates to some random values\r\n  x = random16();\r\n  y = random16();\r\n  z = random16();\r\n}\r\n\/\/ Fill the x\/y array of 8-bit noise values using the inoise8 function.\r\nvoid\u00a0fillnoise8()\u00a0{\r\n  uint8_t dataSmoothing = 0;\r\n  if( speed < 50) {\r\n    dataSmoothing = 200 - (speed * 4);\r\n  }\r\n  \r\n  for(int i = 0; i < MAX_DIMENSION; i++) {\r\n    int ioffset = scale * i;\r\n    for(int j = 0; j < MAX_DIMENSION; j++) {\r\n      int joffset = scale * j;\r\n      \r\n      uint8_t data = inoise8(x + ioffset,y + joffset,z);\r\n\r\n\r\n      data = qsub8(data,16);\r\n      data = qadd8(data,scale8(data,39));\r\n\r\n\r\n      if( dataSmoothing ) {\r\n        uint8_t olddata = noise[i][j];\r\n        uint8_t newdata = scale8( olddata, dataSmoothing) + scale8( data, 256 - dataSmoothing);\r\n        data = newdata;\r\n      }\r\n      \r\n      noise[i][j] = data;\r\n    }\r\n  }\r\n  \r\n\u00a0\u00a0z\u00a0+=\u00a0speed;\r\n  \/\/ apply slow drift to X and Y, just for visual variation.\r\n  x += speed \/ 8;\r\n  y -= speed \/ 16;\r\n}\r\n\r\n\r\nvoid mapNoiseToLEDsUsingPalette()\r\n{\r\n  static uint8_t ihue=0;\r\n  \r\n  for(int i = 0; i < kMatrixWidth; i++) {\r\n    for(int j = 0; j < kMatrixHeight; j++) {\r\n\r\n\r\n      uint8_t index = noise[j][i];\r\n      uint8_t bri =   noise[i][j];\r\n\r\n\r\n      if( colorLoop) { \r\n        index += ihue;\r\n      }\r\n\r\n\r\n      if( bri > 127 ) {\r\n        bri = 255;\r\n      } else {\r\n        bri = dim8_raw( bri * 2);\r\n      }\r\n\r\n\r\n      CRGB color = ColorFromPalette( currentPalette, index, bri);\r\n      leds[XY(i,j)] = color;\r\n    }\r\n  }\r\n  \r\n  ihue+=1;\r\n}\r\n\r\n\r\nvoid loop() {\r\n  \/\/ Periodically choose a new palette, speed, and scale\r\n  ChangePaletteAndSettingsPeriodically();\r\n\r\n\r\n  fillnoise8();\r\n\r\n\r\n  mapNoiseToLEDsUsingPalette();\r\n\r\n\r\n  LEDS.show();\r\n  \/\/ delay(10);\r\n}\r\n\r\n\r\n#define\u00a0HOLD_PALETTES_X_TIMES_AS_LONG\u00a01\r\nvoid ChangePaletteAndSettingsPeriodically()\r\n{\r\n  uint8_t secondHand = ((millis() \/ 1000) \/ HOLD_PALETTES_X_TIMES_AS_LONG) % 60;\r\n  static uint8_t lastSecond = 99;\r\n  \r\n  if( lastSecond != secondHand) {\r\n    lastSecond = secondHand;\r\n    if( secondHand ==  0)  { currentPalette = RainbowColors_p;         speed = 20; scale = 30; colorLoop = 1; }\r\n    if( secondHand ==  5)  { SetupPurpleAndGreenPalette();             speed = 10; scale = 50; colorLoop = 1; }\r\n    if( secondHand == 10)  { SetupBlackAndWhiteStripedPalette();       speed = 20; scale = 30; colorLoop = 1; }\r\n    if( secondHand == 15)  { currentPalette = ForestColors_p;          speed =  8; scale =120; colorLoop = 0; }\r\n    if( secondHand == 20)  { currentPalette = CloudColors_p;           speed =  4; scale = 30; colorLoop = 0; }\r\n    if( secondHand == 25)  { currentPalette = LavaColors_p;            speed =  8; scale = 50; colorLoop = 0; }\r\n    if( secondHand == 30)  { currentPalette = OceanColors_p;           speed = 20; scale = 90; colorLoop = 0; }\r\n    if( secondHand == 35)  { currentPalette = PartyColors_p;           speed = 20; scale = 30; colorLoop = 1; }\r\n    if( secondHand == 40)  { SetupRandomPalette();                     speed = 20; scale = 20; colorLoop = 1; }\r\n    if( secondHand == 45)  { SetupRandomPalette();                     speed = 50; scale = 50; colorLoop = 1; }\r\n    if( secondHand == 50)  { SetupRandomPalette();                     speed = 90; scale = 90; colorLoop = 1; }\r\n    if( secondHand == 55)  { currentPalette = RainbowStripeColors_p;   speed = 30; scale = 20; colorLoop = 1; }\r\n  }\r\n}\r\n\r\n\r\nvoid SetupRandomPalette()\r\n{\r\n  currentPalette = CRGBPalette16( \r\n                      CHSV( random8(), 255, 32), \r\n                      CHSV( random8(), 255, 255), \r\n                      CHSV( random8(), 128, 255), \r\n                      CHSV( random8(), 255, 255)); \r\n}\r\n\r\n\r\nvoid SetupBlackAndWhiteStripedPalette()\r\n{\r\n  \/\/ 'black out' all 16 palette entries...\r\n  fill_solid( currentPalette, 16, CRGB::Black);\r\n  \/\/ and set every fourth one to white.\r\n  currentPalette[0] = CRGB::White;\r\n  currentPalette[4] = CRGB::White;\r\n  currentPalette[8] = CRGB::White;\r\n\u00a0\u00a0currentPalette[12]\u00a0=\u00a0CRGB::White;\r\n}\r\n\/\/ This function sets up a palette of purple and green stripes.\r\nvoid SetupPurpleAndGreenPalette()\r\n{\r\n  CRGB purple = CHSV( HUE_PURPLE, 255, 255);\r\n  CRGB green  = CHSV( HUE_GREEN, 255, 255);\r\n  CRGB black  = CRGB::Black;\r\n  \r\n  currentPalette = CRGBPalette16( \r\n    green,  green,  black,  black,\r\n    purple, purple, black,  black,\r\n    green,  green,  black,  black,\r\n    purple, purple, black,  black );\r\n}\r\n\r\n\r\nuint16_t XY( uint8_t x, uint8_t y)\r\n{\r\n  uint16_t i;\r\n  if( kMatrixSerpentineLayout == false) {\r\n    i = (y * kMatrixWidth) + x;\r\n  }\r\n  if( kMatrixSerpentineLayout == true) {\r\n    if( y & 0x01) {\r\n      \/\/ Odd rows run backwards\r\n      uint8_t reverseX = (kMatrixWidth - 1) - x;\r\n      i = (y * kMatrixWidth) + reverseX;\r\n    } else {\r\n      \/\/ Even rows run forwards\r\n      i = (y * kMatrixWidth) + x;\r\n    }\r\n  }\r\n  return i;\r\n}<\/led_type,led_pin,color_order><\/pre>\n

\u00a0
\n\u4ee5\u4e0b\u662f\u9700\u8981\u4ece\u793a\u4f8b\u4e2d\u9700\u8981\u66f4\u6539\u7684\u4e00\u4e9b\u5185\u5bb9\uff1a<\/p>\n

#define LED_PIN     9\r\n#define BRIGHTNESS  96\r\n#define LED_TYPE    WS2811\r\n#define COLOR_ORDER GRB\r\n\r\n\r\nconst uint8_t kMatrixWidth  = 16;\r\nconst uint8_t kMatrixHeight = 8;\r\nconst bool    kMatrixSerpentineLayout = false;<\/pre>\n

\u00a0 \u6839\u636e\u8fde\u63a5\u7684 Pin \u66f4\u6539LED_PIN\uff0c\u4eae\u5ea6\u4e5f\u53ef\u4ee5\u63a7\u5236\u57280-255\u3002kMatrix\u5bbd\u5ea6\u548c\u9ad8\u5ea6\u4e5f\u9700\u8981\u6839\u636e\u77e9\u9635\u5e03\u5c40\uff0816x8\uff09\u8fdb\u884c\u66f4\u6539\u3002kMatrixSerpentineLayout \u9700\u8981\u8bbe\u7f6e\u4e3a false\u3002\"45c2ae3e-5ea4-11ed-8abf-dac502259ad0\"\u00a0<\/p>\n

 <\/p>\n

\u6700\u57fa\u7840\u7684LED\u9a71\u52a8<\/u>\u5c31\u5b8c\u6210\u4e86\uff0c\u63a5\u4e0b\u6765\u53ef\u4ee5\u505a\u66f4\u5927\u7684\u77e9\u9635\uff0c\u6bd4\u598216x16 \u751a\u81f3\u66f4\u5927\uff0c\u5e76\u4f7f\u7528\u8f6f\u4ef6\u5c06\u4e00\u4e9b\u89c6\u9891<\/u>\u6295\u5f71\u5230\u77e9\u9635\u4e0a\uff0c\u76ee\u6807\u662f\u901a\u8fc7\u6dfb\u52a0\u66f4\u591a\u50cf\u7d20\u6e05\u695a\u5730\u770b\u5230\u6295\u5f71\u5728\u77e9\u9635\u4e0a\u7684\u89c6\u9891\u6216\u56fe\u50cf\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u4e00\u4e2a\u5b8c\u5168\u4ece\u5934\u5f00\u59cb\u5236\u4f5c\u7684\u81ea\u5b9a\u4e49\u77e9\u9635\u5236\u4f5c\uff0c\u60f3\u8981\u73a9\u7684\u5c0f\u4f19\u4f34\u8bd5\u8bd5\u770b\u5427\u3002 \u9996\u5148\u662fLED\u77e9\u9635\u7684\u5e03\u5c40\uff0c\u8be5\u77e9\u9635\u91c7\u7528 16×8 […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[],"_links":{"self":[{"href":"http:\/\/www.szryc.com\/index.php?rest_route=\/wp\/v2\/posts\/10650"}],"collection":[{"href":"http:\/\/www.szryc.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.szryc.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.szryc.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.szryc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10650"}],"version-history":[{"count":1,"href":"http:\/\/www.szryc.com\/index.php?rest_route=\/wp\/v2\/posts\/10650\/revisions"}],"predecessor-version":[{"id":10659,"href":"http:\/\/www.szryc.com\/index.php?rest_route=\/wp\/v2\/posts\/10650\/revisions\/10659"}],"wp:attachment":[{"href":"http:\/\/www.szryc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10650"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.szryc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10650"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.szryc.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10650"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}