很多人都会觉得闪电云应该要有声音,所以这里把怎么给闪电云加上声音的方法也大概也写一下吧。
给闪电云加声音需要额外购买一个模块ISD1820模块。
首先一般来说拿到手的模块是没有把喇叭焊起来的,所以需要自己焊接。
另外ISD1820会自带两个跳线,我们这里是没什么用的,就拔了就好。
然后对原有的电路进行改造,nano上之前应该还会空余一个GND,加上ISD1820上有两个VCC,恰好够所以就不需要扩展VCC和GND了。
连好电路后, 给arduino上电。按住ISD1820模块上的红色REC按钮,就可以录音了。
我们在网上随便找一个雷电的声音。比如google 雷电后第一个网页http://tw.yisell.com/search.htm?w=%E9%96%83%E9%9B%BB
把电脑的声音调到最大用模块上的麦克风对准电脑,按下录音按钮,然后播放声音就可以了。这个过程只需要做一次。录音模块会把这段声音存储下来,即使断电也不会丢失。
然后需要对代码进行改造。
#include <Adafruit_NeoPixel.h>
#define PIXEL_PIN 6 //灯条链接引脚
#define SENSOR_PIN 9 //传感器链接引脚
#define SPEAKER_PIN 13 //录音模块的引脚
#define PIXEL_COUNT 8 //灯珠的个数
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);
int randomNumber;
void setup() {
pinMode(SPEAKER_PIN, OUTPUT);
digitalWrite(SPEAKER_PIN, LOW);
strip.begin();
strip.show(); // Initialize all pixels to 'off'
pinMode(SENSOR_PIN, INPUT);
randomSeed(analogRead(0));
Serial.begin(9600);
}
void loop() {
if( digitalRead(SENSOR_PIN) == HIGH){
digitalWrite(SPEAKER_PIN, HIGH);
randomNumber = random(300);
Serial.println(randomNumber % 61);
thunder_strike(randomNumber % 61);
delay(3000);
digitalWrite(SPEAKER_PIN, LOW);
}else{
if(millis() % 100000 == 0){
for(int i=20; i<100; i++){
colorWipe(strip.Color(i,i-20,0),0);
}
for(int i=100; i>20; i--){
colorWipe(strip.Color(i,i-20,0),0);
}
colorWipe(strip.Color(0,0,0),0);
delay(3000);
}
}
}
void thunder_strike( int type) {
if(type < 20){
colorWipe_short(0, PIXEL_COUNT, strip.Color(73, 147, 255), 3);
colorWipe(strip.Color(0, 0, 0), 0);
delay(500);
colorWipe_short(0, PIXEL_COUNT, strip.Color(73, 147, 255), 3);
delay(20);
colorWipe(strip.Color(0, 0, 0), 0);
delay(500);
}else if(type < 40){
colorWipe(strip.Color(104, 94, 94), 3);
colorWipe(strip.Color(0,0,0), 0);
delay(500);
colorWipe(strip.Color(104, 94, 94), 3);
delay(20);
colorWipe(strip.Color(0,0,0), 0);
delay(500);
}else if(type < 60){
colorWipe(strip.Color(181, 165, 95), 3);
delay(1000);
colorWipe(strip.Color(0,0,0), 0);
delay(100);
colorWipe(strip.Color(181, 165, 95), 3);
delay(500);
colorWipe(strip.Color(0,0,0), 0);
delay(500);
}else{
rainbowCycle(5);
colorWipe(strip.Color(0,0,0), 0);
}
}
void colorWipe_short(uint16_t be, uint16_t en, uint32_t c, uint8_t wait){
for (uint16_t i = be; i < en; i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}
// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
for (uint16_t i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}
void rainbow(uint8_t wait) {
uint16_t i, j;
for (j = 0; j < 256; j++) {
for (i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel((i + j) & 255));
}
strip.show();
delay(wait);
}
}
// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
uint16_t i, j;
for (j = 0; j < 256 * 5; j++) { // 5 cycles of all colors on wheel
for (i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
}
strip.show();
delay(wait);
}
}
//Theatre-style crawling lights.
void theaterChase(uint32_t c, uint8_t wait) {
for (int j = 0; j < 10; j++) { //do 10 cycles of chasing
for (int q = 0; q < 3; q++) {
for (int i = 0; i < strip.numPixels(); i = i + 3) {
strip.setPixelColor(i + q, c); //turn every third pixel on
}
strip.show();
delay(wait);
for (int i = 0; i < strip.numPixels(); i = i + 3) {
strip.setPixelColor(i + q, 0); //turn every third pixel off
}
}
}
}
//Theatre-style crawling lights with rainbow effect
void theaterChaseRainbow(uint8_t wait) {
for (int j = 0; j < 256; j++) { // cycle all 256 colors in the wheel
for (int q = 0; q < 3; q++) {
for (int i = 0; i < strip.numPixels(); i = i + 3) {
strip.setPixelColor(i + q, Wheel( (i + j) % 255)); //turn every third pixel on
}
strip.show();
delay(wait);
for (int i = 0; i < strip.numPixels(); i = i + 3) {
strip.setPixelColor(i + q, 0); //turn every third pixel off
}
}
}
}
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if (WheelPos < 85) {
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if (WheelPos < 170) {
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
然后对原有的电路进行改造,nano上之前应该还会空余一个GND
不过这样做出来的声音会有些小,如果觉得不够的话就需要再加一个功放模块。但是接线之类的会变得复杂很多。