二楼点灯及播放音乐
点灯及播放音乐
这次我使用了高效率的arduino开发,开发环境在这里不再说了点灯我们用的是WS2812,arduino有现成的库,我下载的是这个

程序如下
#include <Adafruit_NeoPixel.h>
#define WS2811_PIN D1
#define MAX_LED 12
Adafruit_NeoPixel strip = Adafruit_NeoPixel( MAX_LED, WS2811_PIN, NEO_RGB + NEO_KHZ800 );
uint8 RGB[][3] = {
  { 0xFF, 0x00, 0x00 },
  { 0x00, 0xFF, 0xFF },
  { 0x00, 0x00, 0xFF },
  { 0x00, 0x00, 0xA0 },
  { 0xFF, 0x00, 0x80 },
  { 0x80, 0x00, 0x80 },
  { 0xFF, 0xFF, 0x00 },
  { 0x00, 0xFF, 0x00 },
  { 0xFF, 0x00, 0xFF },
  { 0xFF, 0xFF, 0xFF },
  { 0xC0, 0xC0, 0xC0 },
  { 0x00, 0x00, 0x00 },
  { 0xFF, 0x80, 0x40 },
  { 0x80, 0x40, 0x00 },
  { 0x80, 0x00, 0x00 },
  { 0x80, 0x80, 0x00 },
  { 0x40, 0x80, 0x80 }
};
void setup() {
  strip.begin();
  // 初始化时关闭所有LED
  strip.show();
}
void loop() {
  // 循环输出七彩色
  for (uint16_t i = 0; i < sizeof(RGB) / sizeof(RGB[0]); i++)
  {
    // 设置颜色,参数为 R G B,范围0-255
    uint32_t color = strip.Color(RGB[i][0], RGB[i][1], RGB[i][2]);;
    for (uint16_t j = 0; j < MAX_LED; j++)
    {
      strip.setPixelColor(j, color);
    }
    // 发送数据并显示
    strip.show();
    // 延时500毫秒
    delay(500);
  }
}
播放音乐
同样,这个模块arduino同样有库,所以哦吼

程序如下
#include "DFRobotDFPlayerMini.h"
DFRobotDFPlayerMini myDFPlayer;
void setup() {
  Serial.begin (9600);
  myDFPlayer.begin(Serial);
  myDFPlayer.volume(20);  //Set volume value. From 0 to 30
  myDFPlayer.play(1);  //Play the first mp3
  myDFPlayer.next();//Play the next mp3
}
void loop() {
    delay(500);
  }
}