3386

帖子

0

TA的资源

五彩晶圆(中级)

21
 

实验场景图 

 

 

 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

22
 

实验开源图形编程(Mind+、编玩边学)

 

 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

23
 

实验场景图

 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

24
 

实验开源图形编程(Mind+、编玩边学)

 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

25
 

实验场景图  动态图

 

 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

26
 

实验开源图形编程(Mind+、编玩边学)

 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

27
 

实验场景图

 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

28
 

实验开源图形编程(Mind+、编玩边学)

 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

29
 

实验场景图

 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

30
 

实验开源图形编程(Mind+、编玩边学)

 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

31
 

实验场景图

 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

32
 

  【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)

  实验二百一十四:WS2812B全彩RGB像素屏 8x32点阵LED显示屏 硬屏模块

  项目程序之七:按键控制进入九种变幻彩灯程序

 

  • /*
  • 【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
  • 实验二百一十四:WS2812B全彩RGB像素屏 8x32点阵LED显示屏 硬屏模块
  • 项目程序之七:按键控制进入九种变幻彩灯程序
  • */
  • #include <Adafruit_NeoPixel.h>
  • #ifdef __AVR__
  • #include <avr/power.h> // Required for 16 MHz Adafruit Trinket
  • #endif
  • // Digital IO pin connected to the button. This will be driven with a
  • // pull-up resistor so the switch pulls the pin to ground momentarily.
  • // On a high -> low transition the button press logic will execute.
  • #define BUTTON_PIN 2
  • #define PIXEL_PIN 6 // Digital IO pin connected to the NeoPixels.
  • #define PIXEL_COUNT 256 // Number of NeoPixels
  • // Declare our NeoPixel strip object:
  • Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);
  • // Argument 1 = Number of pixels in NeoPixel strip
  • // Argument 2 = Arduino pin number (most are valid)
  • // Argument 3 = Pixel type flags, add together as needed:
  • // NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
  • // NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
  • // NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
  • // NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
  • // NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
  • boolean oldState = HIGH;
  • int mode = 0; // Currently-active animation mode, 0-9
  • void setup() {
  • pinMode(BUTTON_PIN, INPUT_PULLUP);
  • strip.begin(); // Initialize NeoPixel strip object (REQUIRED)
  • strip.show(); // Initialize all pixels to 'off'
  • }
  • void loop() {
  • // Get current button state.
  • boolean newState = digitalRead(BUTTON_PIN);
  • // Check if state changed from high to low (button press).
  • if ((newState == LOW) && (oldState == HIGH)) {
  • // Short delay to debounce button.
  • delay(1);
  • // Check if button is still low after debounce.
  • newState = digitalRead(BUTTON_PIN);
  • if (newState == LOW) { // Yes, still low
  • if (++mode > 8) mode = 0; // Advance to next mode, wrap around after #8
  • switch (mode) { // Start the new animation...
  • case 0:
  • colorWipe(strip.Color( 0, 0, 0), 50); // Black/off
  • break;
  • case 1:
  • colorWipe(strip.Color(255, 0, 0), 50); // Red
  • break;
  • case 2:
  • colorWipe(strip.Color( 0, 255, 0), 50); // Green
  • break;
  • case 3:
  • colorWipe(strip.Color( 0, 0, 255), 50); // Blue
  • break;
  • case 4:
  • theaterChase(strip.Color(127, 127, 127), 50); // White
  • break;
  • case 5:
  • theaterChase(strip.Color(127, 0, 0), 50); // Red
  • break;
  • case 6:
  • theaterChase(strip.Color( 0, 0, 127), 50); // Blue
  • break;
  • case 7:
  • rainbow(10);
  • break;
  • case 8:
  • theaterChaseRainbow(50);
  • break;
  • }
  • }
  • }
  • // Set the last-read button state to the old state.
  • oldState = newState;
  • }
  • // Fill strip pixels one after another with a color. Strip is NOT cleared
  • // first; anything there will be covered pixel by pixel. Pass in color
  • // (as a single 'packed' 32-bit value, which you can get by calling
  • // strip.Color(red, green, blue) as shown in the loop() function above),
  • // and a delay time (in milliseconds) between pixels.
  • void colorWipe(uint32_t color, int wait) {
  • for (int i = 0; i < strip.numPixels(); i++) { // For each pixel in strip...
  • strip.setPixelColor(i, color); // Set pixel's color (in RAM)
  • strip.show(); // Update strip to match
  • delay(30); // Pause for a moment
  • }
  • }
  • // Theater-marquee-style chasing lights. Pass in a color (32-bit value,
  • // a la strip.Color(r,g,b) as mentioned above), and a delay time (in ms)
  • // between frames.
  • void theaterChase(uint32_t color, int wait) {
  • for (int a = 0; a < 10; a++) { // Repeat 10 times...
  • for (int b = 0; b < 3; b++) { // 'b' counts from 0 to 2...
  • strip.clear(); // Set all pixels in RAM to 0 (off)
  • // 'c' counts up from 'b' to end of strip in steps of 3...
  • for (int c = b; c < strip.numPixels(); c += 3) {
  • strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
  • }
  • strip.show(); // Update strip with new contents
  • delay(30); // Pause for a moment
  • }
  • }
  • }
  • // Rainbow cycle along whole strip. Pass delay time (in ms) between frames.
  • void rainbow(int wait) {
  • // Hue of first pixel runs 3 complete loops through the color wheel.
  • // Color wheel has a range of 65536 but it's OK if we roll over, so
  • // just count from 0 to 3*65536. Adding 256 to firstPixelHue each time
  • // means we'll make 3*65536/256 = 768 passes through this outer loop:
  • for (long firstPixelHue = 0; firstPixelHue < 3 * 65536; firstPixelHue += 256) {
  • for (int i = 0; i < strip.numPixels(); i++) { // For each pixel in strip...
  • // Offset pixel hue by an amount to make one full revolution of the
  • // color wheel (range of 65536) along the length of the strip
  • // (strip.numPixels() steps):
  • int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
  • // strip.ColorHSV() can take 1 or 3 arguments: a hue (0 to 65535) or
  • // optionally add saturation and value (brightness) (each 0 to 255).
  • // Here we're using just the single-argument hue variant. The result
  • // is passed through strip.gamma32() to provide 'truer' colors
  • // before assigning to each pixel:
  • strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
  • }
  • strip.show(); // Update strip with new contents
  • delay(30); // Pause for a moment
  • }
  • }
  • // Rainbow-enhanced theater marquee. Pass delay time (in ms) between frames.
  • void theaterChaseRainbow(int wait) {
  • int firstPixelHue = 0; // First pixel starts at red (hue 0)
  • for (int a = 0; a < 30; a++) { // Repeat 30 times...
  • for (int b = 0; b < 3; b++) { // 'b' counts from 0 to 2...
  • strip.clear(); // Set all pixels in RAM to 0 (off)
  • // 'c' counts up from 'b' to end of strip in increments of 3...
  • for (int c = b; c < strip.numPixels(); c += 3) {
  • // hue of pixel 'c' is offset by an amount to make one full
  • // revolution of the color wheel (range 65536) along the length
  • // of the strip (strip.numPixels() steps):
  • int hue = firstPixelHue + c * 65536L / strip.numPixels();
  • uint32_t color = strip.gamma32(strip.ColorHSV(hue)); // hue -> RGB
  • strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
  • }
  • strip.show(); // Update strip with new contents
  • delay(30); // Pause for a moment
  • firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames
  • }
  • }
  • }

 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

33
 

实验场景图

 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

34
 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

35
 

  【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)

  实验二百一十四:WS2812B全彩RGB像素屏 8x32点阵LED显示屏 硬屏模块

  项目程序之八:多彩颜色调色板

 

  • /*
  • 【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
  • 实验二百一十四:WS2812B全彩RGB像素屏 8x32点阵LED显示屏 硬屏模块
  • 项目程序之八:多彩颜色调色板
  • */
  • #include <FastLED.h>
  • #define LED_PIN 6
  • #define NUM_LEDS 256
  • #define BRIGHTNESS 23
  • #define LED_TYPE WS2811
  • #define COLOR_ORDER GRB
  • CRGB leds[NUM_LEDS];
  • #define UPDATES_PER_SECOND 100 //定义每秒更新数
  • // This example shows several ways to set up and use 'palettes' of colors
  • // with FastLED.
  • //
  • // These compact palettes provide an easy way to re-colorize your
  • // animation on the fly, quickly, easily, and with low overhead.
  • //
  • // USING palettes is MUCH simpler in practice than in theory, so first just
  • // run this sketch, and watch the pretty lights as you then read through
  • // the code. Although this sketch has eight (or more) different color schemes,
  • // the entire sketch compiles down to about 6.5K on AVR.
  • //
  • // FastLED provides a few pre-configured color palettes, and makes it
  • // extremely easy to make up your own color schemes with palettes.
  • //
  • // Some notes on the more abstract 'theory and practice' of
  • // FastLED compact palettes are at the bottom of this file.
  • CRGBPalette16 currentPalette;
  • TBlendType currentBlending;
  • extern CRGBPalette16 myRedWhiteBluePalette;
  • extern const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM;
  • void setup() {
  • delay( 3000 ); // power-up safety delay
  • FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  • FastLED.setBrightness( BRIGHTNESS );
  • currentPalette = RainbowColors_p;
  • currentBlending = LINEARBLEND;
  • }
  • void loop()
  • {
  • ChangePalettePeriodically();
  • static uint8_t startIndex = 0;
  • startIndex = startIndex + 1; /* motion speed */
  • FillLEDsFromPaletteColors( startIndex);
  • FastLED.show();
  • FastLED.delay(1000 / UPDATES_PER_SECOND);
  • }
  • void FillLEDsFromPaletteColors( uint8_t colorIndex)
  • {
  • uint8_t brightness = 255;
  • for ( int i = 0; i < NUM_LEDS; ++i) {
  • leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);
  • colorIndex += 3;
  • }
  • }
  • // There are several different palettes of colors demonstrated here.
  • //
  • // FastLED provides several 'preset' palettes: RainbowColors_p, RainbowStripeColors_p,
  • // OceanColors_p, CloudColors_p, LavaColors_p, ForestColors_p, and PartyColors_p.
  • //
  • // Additionally, you can manually define your own color palettes, or you can write
  • // code that creates color palettes on the fly. All are shown here.
  • void ChangePalettePeriodically()
  • {
  • uint8_t secondHand = (millis() / 1000) % 60;
  • static uint8_t lastSecond = 99;
  • if ( lastSecond != secondHand) {
  • lastSecond = secondHand;
  • if ( secondHand == 0) {
  • currentPalette = RainbowColors_p;
  • currentBlending = LINEARBLEND;
  • }
  • if ( secondHand == 10) {
  • currentPalette = RainbowStripeColors_p;
  • currentBlending = NOBLEND;
  • }
  • if ( secondHand == 15) {
  • currentPalette = RainbowStripeColors_p;
  • currentBlending = LINEARBLEND;
  • }
  • if ( secondHand == 20) {
  • SetupPurpleAndGreenPalette();
  • currentBlending = LINEARBLEND;
  • }
  • if ( secondHand == 25) {
  • SetupTotallyRandomPalette();
  • currentBlending = LINEARBLEND;
  • }
  • if ( secondHand == 30) {
  • SetupBlackAndWhiteStripedPalette();
  • currentBlending = NOBLEND;
  • }
  • if ( secondHand == 35) {
  • SetupBlackAndWhiteStripedPalette();
  • currentBlending = LINEARBLEND;
  • }
  • if ( secondHand == 40) {
  • currentPalette = CloudColors_p;
  • currentBlending = LINEARBLEND;
  • }
  • if ( secondHand == 45) {
  • currentPalette = PartyColors_p;
  • currentBlending = LINEARBLEND;
  • }
  • if ( secondHand == 50) {
  • currentPalette = myRedWhiteBluePalette_p;
  • currentBlending = NOBLEND;
  • }
  • if ( secondHand == 55) {
  • currentPalette = myRedWhiteBluePalette_p;
  • currentBlending = LINEARBLEND;
  • }
  • }
  • }
  • // This function fills the palette with totally random colors.
  • void SetupTotallyRandomPalette()
  • {
  • for ( int i = 0; i < 16; ++i) {
  • currentPalette[i] = CHSV( random8(), 255, random8());
  • }
  • }
  • // This function sets up a palette of black and white stripes,
  • // using code. Since the palette is effectively an array of
  • // sixteen CRGB colors, the various fill_* functions can be used
  • // to set them up.
  • void SetupBlackAndWhiteStripedPalette()
  • {
  • // 'black out' all 16 palette entries...
  • fill_solid( currentPalette, 16, CRGB::Black);
  • // and set every fourth one to white.
  • currentPalette[0] = CRGB::White;
  • currentPalette[4] = CRGB::White;
  • currentPalette[8] = CRGB::White;
  • currentPalette[12] = CRGB::White;
  • }
  • // This function sets up a palette of purple and green stripes.
  • void SetupPurpleAndGreenPalette()
  • {
  • CRGB purple = CHSV( HUE_PURPLE, 255, 255);
  • CRGB green = CHSV( HUE_GREEN, 255, 255);
  • CRGB black = CRGB::Black;
  • currentPalette = CRGBPalette16(
  • green, green, black, black,
  • purple, purple, black, black,
  • green, green, black, black,
  • purple, purple, black, black );
  • }
  • // This example shows how to set up a static color palette
  • // which is stored in PROGMEM (flash), which is almost always more
  • // plentiful than RAM. A static PROGMEM palette like this
  • // takes up 64 bytes of flash.
  • const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM =
  • {
  • CRGB::Red,
  • CRGB::Gray, // 'white' is too bright compared to red and blue
  • CRGB::Blue,
  • CRGB::Black,
  • CRGB::Red,
  • CRGB::Gray,
  • CRGB::Blue,
  • CRGB::Black,
  • CRGB::Red,
  • CRGB::Red,
  • CRGB::Gray,
  • CRGB::Gray,
  • CRGB::Blue,
  • CRGB::Blue,
  • CRGB::Black,
  • CRGB::Black
  • };
  • // Additional notes on FastLED compact palettes:
  • //
  • // Normally, in computer graphics, the palette (or "color lookup table")
  • // has 256 entries, each containing a specific 24-bit RGB color. You can then
  • // index into the color palette using a simple 8-bit (one byte) value.
  • // A 256-entry color palette takes up 768 bytes of RAM, which on Arduino
  • // is quite possibly "too many" bytes.
  • //
  • // FastLED does offer traditional 256-element palettes, for setups that
  • // can afford the 768-byte cost in RAM.
  • //
  • // However, FastLED also offers a compact alternative. FastLED offers
  • // palettes that store 16 distinct entries, but can be accessed AS IF
  • // they actually have 256 entries; this is accomplished by interpolating
  • // between the 16 explicit entries to create fifteen intermediate palette
  • // entries between each pair.
  • //
  • // So for example, if you set the first two explicit entries of a compact
  • // palette to Green (0,255,0) and Blue (0,0,255), and then retrieved
  • // the first sixteen entries from the virtual palette (of 256), you'd get
  • // Green, followed by a smooth gradient from green-to-blue, and then Blue.

 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

36
 

实验场景图  动态图

 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

37
 

实验开源仿真编程(Linkboy V4.63)

 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

38
 

实验开源仿真编程(Linkboy V4.63)

 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

39
 

实验开源仿真编程(Linkboy V4.63)

 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

40
 

实验场景图

 

 
 
 

回复
您需要登录后才可以回帖 登录 | 注册

猜你喜欢
随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/10 下一条
【有奖直播】2025是德科技数字月-数字新品来助阵
直播时间:3月19日(周三)14:00
直播奖励:小米口红充电宝、倍思充电线、是德科技十周年鼠标垫

查看 »

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

 
机器人开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表