极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 17234|回复: 8

aduino控制2811下面的流水灯程序要怎样才能反过来跑?程序要改那里?

[复制链接]
发表于 2016-2-22 15:53:56 | 显示全部楼层 |阅读模式

请高手们帮小弟一把~!

#include <Adafruit_NeoPixel.h>
#define PIN 6       //#定義6 PIN
Adafruit_NeoPixel strip = Adafruit_NeoPixel(136, PIN, NEO_GRB + NEO_KHZ800);       //整条灯长度
void setup() {           //無效設置(){
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'        strip.show(); //初始化所有像素“關”
}
void loop() {     //空隙環(){
rainbowCycle(10);//5速度,越细越快
}
void rainbowCycle(uint8_t wait) //無效rainbowCycle(uint8_t有等待){
  {      
  uint16_t i,j;
  for(j=0; j<256*5; j++)
       {
    for(i=0; i< strip.numPixels(); i++)
         {         
              strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));  
                }
    strip.show();
    delay(wait);        //    延遲(等待);
  }
}


uint32_t Wheel(byte WheelPos) {              

  if(WheelPos < 30)//拖尾长度
       {                     
               return strip.Color( WheelPos ,WheelPos , WheelPos );   //前跑馬灯颜色     
        }
               else
                 {                  
                     return strip.Color( 0, 0, 0);     //背景灯光颜色            
                 }
}
回复

使用道具 举报

发表于 2016-2-22 16:51:42 | 显示全部楼层
strip.setPixelColor(strip.numPixels()-i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));  

改成这样试试看?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2016-2-23 11:00:29 | 显示全部楼层
好的!我试试!
太感谢了!
回复 支持 反对

使用道具 举报

 楼主| 发表于 2016-2-23 12:03:48 | 显示全部楼层
zoologist 发表于 2016-2-22 16:51
strip.setPixelColor(strip.numPixels()-i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));  

改成 ...

流水灯可以反跑了!太感谢了!

还发现还有一个问题,流水灯跑的时候,前面的灯暗渐变到后面的灯亮!
大神~~我要怎样才能反过来?


回复 支持 反对

使用道具 举报

发表于 2016-2-23 12:29:48 | 显示全部楼层
crbgz 发表于 2016-2-23 12:03
流水灯可以反跑了!太感谢了!

还发现还有一个问题,流水灯跑的时候,前面的灯暗渐变到后面的灯亮!
...

呃  你这个库我没用过

需要你自己琢磨一下了
回复 支持 反对

使用道具 举报

 楼主| 发表于 2016-2-23 16:15:36 | 显示全部楼层
zoologist 发表于 2016-2-23 12:29
呃  你这个库我没用过

需要你自己琢磨一下了

嗯!好的!太谢谢你了!
回复 支持 反对

使用道具 举报

 楼主| 发表于 2016-2-24 09:17:54 | 显示全部楼层
crbgz 发表于 2016-2-23 16:15
嗯!好的!太谢谢你了!

大侠还是琢磨不出来~~~

麻烦你再帮我看看~~~

/*--------------------------------------------------------------------
  This file is part of the Adafruit NeoPixel library.

  NeoPixel is free software: you can redistribute it and/or modify
  it under the terms of the GNU Lesser General Public License as
  published by the Free Software Foundation, either version 3 of
  the License, or (at your option) any later version.

  NeoPixel is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with NeoPixel.  If not, see
  <http://www.gnu.org/licenses/>.
  --------------------------------------------------------------------*/

#ifndef ADAFRUIT_NEOPIXEL_H
#define ADAFRUIT_NEOPIXEL_H

#if (ARDUINO >= 100)
#include <Arduino.h>
#else
#include <WProgram.h>
#include <pins_arduino.h>
#endif

// 'type' flags for LED pixels (third parameter to constructor):
#define NEO_RGB     0x00 // Wired for RGB data order
#define NEO_GRB     0x01 // Wired for GRB data order
#define NEO_BRG     0x04
  
#define NEO_COLMASK 0x01
#define NEO_KHZ800  0x02 // 800 KHz datastream
#define NEO_SPDMASK 0x02
// Trinket flash space is tight, v1 NeoPixels aren't handled by default.
// Remove the ifndef/endif to add support -- but code will be bigger.
// Conversely, can comment out the #defines to save space on other MCUs.
#ifndef __AVR_ATtiny85__
#define NEO_KHZ400  0x00 // 400 KHz datastream
#endif

class Adafruit_NeoPixel {

public:

  // Constructor: number of LEDs, pin number, LED type
  Adafruit_NeoPixel(uint16_t n, uint8_t p=6, uint8_t t=NEO_GRB + NEO_KHZ800);
  ~Adafruit_NeoPixel();

  void
    begin(void),
    show(void),
    setPin(uint8_t p),
    setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b),
    setPixelColor(uint16_t n, uint32_t c),
    setBrightness(uint8_t),
    clear();
  uint8_t
   *getPixels(void) const,
    getBrightness(void) const;
  uint16_t
    numPixels(void) const;
  static uint32_t
    Color(uint8_t r, uint8_t g, uint8_t b);
  uint32_t
    getPixelColor(uint16_t n) const;
  inline bool
    canShow(void) { return (micros() - endTime) >= 50L; }

private:

  const uint16_t
    numLEDs,       // Number of RGB LEDs in strip
    numBytes;      // Size of 'pixels' buffer below
  uint8_t
    pin,           // Output pin number
    brightness,
   *pixels,        // Holds LED color values (3 bytes each)
    rOffset,       // Index of red byte within each 3-byte pixel
    gOffset,       // Index of green byte
    bOffset;       // Index of blue byte
  const uint8_t
    type;          // Pixel flags (400 vs 800 KHz, RGB vs GRB color)
  uint32_t
    endTime;       // Latch timing reference
#ifdef __AVR__
  const volatile uint8_t
    *port;         // Output PORT register
  uint8_t
    pinMask;       // Output PORT bitmask
#endif

};

#endif // ADAFRUIT_NEOPIXEL_H
回复 支持 反对

使用道具 举报

发表于 2016-7-24 16:27:42 | 显示全部楼层
楼主,你qq多少有事相求
回复 支持 反对

使用道具 举报

发表于 2016-7-25 09:10:08 | 显示全部楼层
zoologist 发表于 2016-2-23 12:29
呃  你这个库我没用过

需要你自己琢磨一下了

楼楼的程序为什么是无限跑,怎样改才能跑一次
回复 支持 反对

使用道具 举报

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

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-15 01:05 , Processed in 0.037361 second(s), 20 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表