[进阶]七彩雷电云

5523浏览
查看: 5523|回复: 2

[进阶] 七彩雷电云

[复制链接]
大大们求救啊,我想做一盏雷电云,人不来的时候是7彩的,有人靠近了就打雷闪电。
这是7彩灯带的代码(灯带是):
[mw_shl_code=applescript,true]#include <Adafruit_NeoPixel.h>
#define PIN 6   
#define LED_COUNT 60
Adafruit_NeoPixel leds = Adafruit_NeoPixel(LED_COUNT, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
  leds.begin();  
  clearLEDs();  
  leds.show();  

}
void loop() {
  for (int i=0; i<LED_COUNT; i++)
  {
    rainbow(i);
    delay(50);  
  }

}
void clearLEDs()
{
  for (int i=0; i<LED_COUNT; i++)
  {
    leds.setPixelColor(i, 0);
  }
}
void rainbow(byte startPosition)
{
  int rainbowScale = 192 / LED_COUNT;
  for (int i=0; i<LED_COUNT; i++)
  {
    leds.setPixelColor(i, rainbowOrder((rainbowScale * (i + startPosition)) % 192));
  }
  leds.show();
}
uint32_t rainbowOrder(byte position)
{
  if (position < 31)  
  {
    return leds.Color(0xFF, position * 8, 0);
  }
  else if (position < 63)  
  {
    position -= 31;
    return leds.Color(0xFF - position * 8, 0xFF, 0);
  }
  else if (position < 95)  
  {
    position -= 63;
    return leds.Color(0, 0xFF, position * 8);
  }
  else if (position < 127)  
  {
    position -= 95;
    return leds.Color(0, 0xFF - position * 8, 0xFF);
  }
  else if (position < 159)
  {
    position -= 127;
    return leds.Color(position * 8, 0, 0xFF);
  }
  else
  {
    position -= 159;
    return leds.Color(0xFF, 0x00, 0xFF - position * 8);
  }
}[/mw_shl_code]
这是雷电云的代码,df下载的:
[mw_shl_code=applescript,true]/*
A total of 48 lights, 8 sections of each of the 6 lights
ByFree
Time2015.10.14
*/
#include <SoftwareSerial.h>
#include <DFPlayer_Mini_Mp3.h>
#include <Adafruit_NeoPixel.h>
#include <avr/power.h>

// Which pin on the Arduino is connected to the Neoled?
// On a Trinket or Gemma we suggest changing this to 1
#define PIN           6
// How many Neoled are attached to the Arduino?
#define LED_COUNT    50
int lednum = 6;
// When we setup the NeoPixel library, we tell it how many led, and which pin to use to send signals.
// Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
// example for more information on possible values.
Adafruit_NeoPixel led = Adafruit_NeoPixel(LED_COUNT, PIN, NEO_GRB + NEO_KHZ800);
int delayval = 0; // delay for half a second
void setup() {
  Serial.begin(9600);
  pinMode(6, OUTPUT);
  mp3_set_serial (Serial);        //set Serial for DFPlayer-mini mp3 module
  mp3_set_volume (30);
  pinMode(3, INPUT);
  // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
#if defined (__AVR_ATtiny85__)
  if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
  // End of trinket special code
  led.begin(); // This initializes the NeoPixel library.
}
void loop() {
  if (digitalRead(3) == 1)
  {
    /* First lightning..........................*/
    for (int z = 0; z < 1; z++) //   Overall cycle number
    { for (int j = 0; j < 4; j++) // A number of circular lights
      {
        // For a set of Neoled the first NeoPixel is 0, second is 1, all the way up to the count of led minus one.
        for (int i = 0 + j * lednum; i < 6 + j * lednum; i++) {
          // led.Color takes RGB values, from 0,0,0 up to 255,255,255
          led.setPixelColor(i, led.Color(255, 255, 255)); //white
          led.show(); // This sends the updated pixel color to the hardware.
          delay(delayval); // Delay for a period of time (in milliseconds).
        }
        delay(10);
        for (int i = 0 + j * lednum; i < 6 + j * lednum; i++) {
          // led.Color takes RGB values, from 0,0,0 up to 255,255,255
          led.setPixelColor(i, led.Color(0, 0, 0));
          led.show(); // This sends the updated pixel color to the hardware.
          delay(delayval); // Delay for a period of time (in milliseconds).
        }
        delay(200);// Each light interval
      }
      delay(500);  //Each cycle of the interval
    }

    delay(2000);
    /* play mp3..........................*/
    mp3_play (1);
    delay(3000); //for light
    /* 2 lightning-------all light..........................*/
    for (int z = 0; z < 2; z++) //   Overall cycle number
    { for (int j = 0; j < 8; j++) // A number of circular lights
      {
        // For a set of Neoled the first NeoPixel is 0, second is 1, all the way up to the count of led minus one.
        for (int i = 0 + j * lednum; i < 6 + j * lednum; i++) {
          // led.Color takes RGB values, from 0,0,0 up to 255,255,255
          led.setPixelColor(i, led.Color(255, 255, 255)); //white
          led.show(); // This sends the updated pixel color to the hardware.
          delay(delayval); // Delay for a period of time (in milliseconds).
        }
      }
      delay(50);// ALL light interval
      for (int j = 0; j < 8; j++) // A number of circular lights
      {
        // For a set of Neoled the first NeoPixel is 0, second is 1, all the way up to the count of led minus one.
        for (int i = 0 + j * lednum; i < 6 + j * lednum; i++) {
          // led.Color takes RGB values, from 0,0,0 up to 255,255,255
          led.setPixelColor(i, led.Color(0, 0, 0)); //white
          led.show(); // This sends the updated pixel color to the hardware.
          delay(delayval); // Delay for a period of time (in milliseconds).
        }
      }
      delay(100);  //Each cycle of the interval
    }
    delay(3000);
    /* 3  lightning..........................*/

    for (int z = 0; z < 1; z++) // for cycle times
    { for (int j = 0; j < 8; j++) //  for  number   everytime
      {
        // For a set of Neoled the first NeoPixel is 0, second is 1, all the way up to the count of led minus one.
        for (int i = 0 + j * lednum; i < 6 + j * lednum; i++) {
          // led.Color takes RGB values, from 0,0,0 up to 255,255,255
          led.setPixelColor(i, led.Color(255, 255, 255)); // Moderately bright green color.
          led.show(); // This sends the updated pixel color to the hardware.
          delay(delayval); // Delay for a period of time (in milliseconds).
        }
        delay(10);
        for (int i = 0 + j * lednum; i < 6 + j * lednum; i++) {
          // led.Color takes RGB values, from 0,0,0 up to 255,255,255
          led.setPixelColor(i, led.Color(0, 0, 0)); // Moderately bright green color.
          led.show(); // This sends the updated pixel color to the hardware.
          delay(delayval); // Delay for a period of time (in milliseconds).
        }
        delay(500);
      }
      delay(500);
    }
    delay(2000);
    /* 4   lightning-------all light..........................*/
    for (int z = 0; z < 2; z++) //   Overall cycle number
    { for (int j = 0; j < 8; j++) // A number of circular lights
      {
        // For a set of Neoled the first NeoPixel is 0, second is 1, all the way up to the count of led minus one.
        for (int i = 0 + j * lednum; i < 6 + j * lednum; i++) {
          // led.Color takes RGB values, from 0,0,0 up to 255,255,255
          led.setPixelColor(i, led.Color(255, 255, 255)); //white
          led.show(); // This sends the updated pixel color to the hardware.
          delay(delayval); // Delay for a period of time (in milliseconds).
        }
        delay(10);
      }
      delay(10);// ALL light interval
      for (int j = 0; j < 8; j++) // A number of circular lights
      {
        // For a set of Neoled the first NeoPixel is 0, second is 1, all the way up to the count of led minus one.
        for (int i = 0 + j * lednum; i < 6 + j * lednum; i++) {
          // led.Color takes RGB values, from 0,0,0 up to 255,255,255
          led.setPixelColor(i, led.Color(0, 0, 0)); //white
          led.show(); // This sends the updated pixel color to the hardware.
          delay(delayval); // Delay for a period of time (in milliseconds).
        }
        delay(10);
      }

      delay(500);  //Each cycle of the interval
    }
  }
  else
    for (int i = 0; i < LED_COUNT; i++) {
      // led.Color takes RGB values, from 0,0,0 up to 255,255,255
      led.setPixelColor(i, led.Color(0, 0, 0)); // Moderately bright green color.
      led.show(); // This sends the updated pixel color to the hardware.
      delay(delayval); // Delay for a period of time (in milliseconds).
    }
}

void clearLEDs()
{
  for (int i = 0; i < LED_COUNT; i++)  led.setPixelColor(i, 0);
}
[/mw_shl_code]

我回来了,人体红外感应不到人的时候显示七彩,感应到人的时候打雷闪电,但是会有杂音,外观做好了上视频
[mw_shl_code=applescript,true]/*
A total of 48 lights, 8 sections of each of the 6 lights
ByFree
Time2015.10.14
*/
#include <SoftwareSerial.h>
#include <DFPlayer_Mini_Mp3.h>
#include <Adafruit_NeoPixel.h>
#include <avr/power.h>

// Which pin on the Arduino is connected to the Neoled?
// On a Trinket or Gemma we suggest changing this to 1
#define PIN           6
// How many Neoled are attached to the Arduino?
#define LED_COUNT    180
int lednum = 24;
// When we setup the NeoPixel library, we tell it how many led, and which pin to use to send signals.
// Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
// example for more information on possible values.
Adafruit_NeoPixel led = Adafruit_NeoPixel(LED_COUNT, PIN, NEO_GRB + NEO_KHZ800);
int delayval = 0; // delay for half a second

void clearLED()
{
  for (int i = 0; i < LED_COUNT; i++)  led.setPixelColor(i, 0);
}
void rainbow(byte startPosition)
{
  int rainbowScale = 192 / LED_COUNT;
  for (int i=0; i<LED_COUNT; i++)
  {
    led.setPixelColor(i, rainbowOrder((rainbowScale * (i + startPosition)) % 192));
  }
  led.show();
}
uint32_t rainbowOrder(byte position)
{
  if (position < 31)
  {
    return led.Color(0xFF, position * 8, 0);
  }
  else if (position < 63)
  {
    position -= 31;
    return led.Color(0xFF - position * 8, 0xFF, 0);
  }
  else if (position < 95)
  {
    position -= 63;
    return led.Color(0, 0xFF, position * 8);
  }
  else if (position < 127)
  {
    position -= 95;
    return led.Color(0, 0xFF - position * 8, 0xFF);
  }
  else if (position < 159)
  {
    position -= 127;
    return led.Color(position * 8, 0, 0xFF);
  }
  else
  {
    position -= 159;
    return led.Color(0xFF, 0x00, 0xFF - position * 8);
  }
}
void setup() {
  Serial.begin(9600);
  pinMode(6, OUTPUT);
  mp3_set_serial (Serial);  //set Serial for DFPlayer-mini mp3 module
  mp3_set_volume (30);
  pinMode(3, INPUT);
  // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
#if defined (__AVR_ATtiny85__)
  if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
  // End of trinket special code
  led.begin(); // This initializes the NeoPixel library.
  clearLED();  
  led.show();
}
void loop() {  
  if (digitalRead(3) == 1)
  {
    /* First lightning..........................*/
    for (int z = 0; z < 1; z++) //   Overall cycle number
    { for (int j = 0; j < 4; j++) // A number of circular lights
      {
        // For a set of Neoled the first NeoPixel is 0, second is 1, all the way up to the count of led minus one.
        for (int i = 0 + j * lednum; i < 6 + j * lednum; i++) {
          // led.Color takes RGB values, from 0,0,0 up to 255,255,255
          led.setPixelColor(i, led.Color(255, 255, 255)); //white
          led.show(); // This sends the updated pixel color to the hardware.
          delay(delayval); // Delay for a period of time (in milliseconds).
        }
        delay(10);
        for (int i = 0 + j * lednum; i < 6 + j * lednum; i++) {
          // led.Color takes RGB values, from 0,0,0 up to 255,255,255
          led.setPixelColor(i, led.Color(0, 0, 0));
          led.show(); // This sends the updated pixel color to the hardware.
          delay(delayval); // Delay for a period of time (in milliseconds).
        }
        delay(200);// Each light interval
      }
      delay(500);  //Each cycle of the interval
    }

    delay(2000);
   
    /* play mp3..........................*/
    mp3_play (1);
    delay(6000); //for light
    /* 2 lightning-------all light..........................*/
    for (int z = 0; z < 2; z++) //   Overall cycle number
    { for (int j = 0; j < 8; j++) // A number of circular lights
      {
        // For a set of Neoled the first NeoPixel is 0, second is 1, all the way up to the count of led minus one.
        for (int i = 0 + j * lednum; i < 6 + j * lednum; i++) {
          // led.Color takes RGB values, from 0,0,0 up to 255,255,255
          led.setPixelColor(i, led.Color(255, 255, 255)); //white
          led.show(); // This sends the updated pixel color to the hardware.
          delay(delayval); // Delay for a period of time (in milliseconds).
        }
      }
      delay(50);// ALL light interval
      for (int j = 0; j < 8; j++) // A number of circular lights
      {
        // For a set of Neoled the first NeoPixel is 0, second is 1, all the way up to the count of led minus one.
        for (int i = 0 + j * lednum; i < 6 + j * lednum; i++) {
          // led.Color takes RGB values, from 0,0,0 up to 255,255,255
          led.setPixelColor(i, led.Color(0, 0, 0)); //white
          led.show(); // This sends the updated pixel color to the hardware.
          delay(delayval); // Delay for a period of time (in milliseconds).
        }
      }
      delay(100);  //Each cycle of the interval
    }
    delay(4000);
    /* 3  lightning..........................*/
   mp3_play (2);
    delay(6000); //for light
    for (int z = 0; z < 1; z++) // for cycle times
    { for (int j = 0; j < 8; j++) //  for  number   everytime
      {
        // For a set of Neoled the first NeoPixel is 0, second is 1, all the way up to the count of led minus one.
        for (int i = 0 + j * lednum; i < 6 + j * lednum; i++) {
          // led.Color takes RGB values, from 0,0,0 up to 255,255,255
          led.setPixelColor(i, led.Color(255, 255, 255)); // Moderately bright green color.
          led.show(); // This sends the updated pixel color to the hardware.
          delay(delayval); // Delay for a period of time (in milliseconds).
        }
        delay(10);
        for (int i = 0 + j * lednum; i < 6 + j * lednum; i++) {
          // led.Color takes RGB values, from 0,0,0 up to 255,255,255
          led.setPixelColor(i, led.Color(0, 0, 0)); // Moderately bright green color.
          led.show(); // This sends the updated pixel color to the hardware.
          delay(delayval); // Delay for a period of time (in milliseconds).
        }
        delay(500);
      }
      delay(500);
    }
    delay(2000);
    mp3_play (3);
    delay(6000); //for light
    /* 4   lightning-------all light..........................*/
    for (int z = 0; z < 2; z++) //   Overall cycle number
    { for (int j = 0; j < 8; j++) // A number of circular lights
      {
        // For a set of Neoled the first NeoPixel is 0, second is 1, all the way up to the count of led minus one.
        for (int i = 0 + j * lednum; i < 6 + j * lednum; i++) {
          // led.Color takes RGB values, from 0,0,0 up to 255,255,255
          led.setPixelColor(i, led.Color(255, 255, 255)); //white
          led.show(); // This sends the updated pixel color to the hardware.
          delay(delayval); // Delay for a period of time (in milliseconds).
        }
        delay(10);
      }
      delay(10);// ALL light interval
      for (int j = 0; j < 8; j++) // A number of circular lights
      {
        // For a set of Neoled the first NeoPixel is 0, second is 1, all the way up to the count of led minus one.
        for (int i = 0 + j * lednum; i < 6 + j * lednum; i++) {
          // led.Color takes RGB values, from 0,0,0 up to 255,255,255
          led.setPixelColor(i, led.Color(0, 0, 0)); //white
          led.show(); // This sends the updated pixel color to the hardware.
          delay(delayval); // Delay for a period of time (in milliseconds).
        }
        delay(10);
      }

      delay(500);  //Each cycle of the interval
    }
    mp3_play (1);
    delay(6000); //for light
  }
  else
  {
   
    for (int i = 0; i < LED_COUNT; i++) {
      // led.Color takes RGB values, from 0,0,0 up to 255,255,255
      //led.setPixelColor(i, led.Color(255, 255, 255)); // Moderately bright green color.
      //led.show(); // This sends the updated pixel color to the hardware.
      //delay(delayval); // Delay for a period of time (in milliseconds).
       rainbow(i);
    delay(50);  
    }
    clearLED();
    led.show();
  }
}
[/mw_shl_code]
视频:
因为我人站的太近一直感应到人没有拍出七彩的效果
电路图我是按照df的来弄的


截图201805031215307950.png

hnyzcj  版主

发表于 2018-4-17 21:42:07

你不是已经有代码了码?那就做起来把
回复

使用道具 举报

1973742214  高级技师

发表于 2018-4-20 20:36:31

图片图片,视频视频,板凳板凳
回复

使用道具 举报

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

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail