吼一声试试

来自Labplus盛思维基百科
跳转至: 导航搜索
吼一声试试.png


概述

本作品可通过声音传感器触发改变彩色RGB灯带颜色。使用时先根据制作说明将作品组装完整,然后接上电源 (9V电池或USB供电),打开主控板开关,触发声音传感器即可。本作品用声音触发器作为输入装置,彩色RGB 灯带作为输出装置,可自行编程改变颜色、变换方式、灯带数量等。DIY动手组装,锻炼动手能力,了解智能创 意电子套件的使用,激发创新思维,增加学习乐趣。

使用教程

程序当检测到有声音触发后,控制10颗ws2812灯珠灯带随机生成颜色并显示。

组装说明

点击下载.png
File:吼一声试试装配.pdf


吼一声试试 装配.png

电子模块清单

模块名称 数量
W1主控板 x1
声音触发器 x1
RGB灯带(10颗) x1

电子模块连接说明

模块 引脚 说明
声音触发器 W1-A0/A1接口
RGB灯带(10颗) W1-2/4接口

Arduino程序/图形化程序

点击下载.png
吼一声试试程序包
#include "Adafruit_NeoPixel.h"

#define s 500
#define SWITCHPIN      A0


int numpixelsPin = 2;
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS      10

Adafruit_NeoPixel pixels1 = Adafruit_NeoPixel(NUMPIXELS, numpixelsPin, NEO_GRB + NEO_KHZ800);
void setup() {
  pinMode(numpixelsPin,OUTPUT);
  digitalWrite(numpixelsPin,LOW);  
  // put your setup code here, to run once:
  pixels1.begin(); // This initializes the NeoPixel library.
  
  pinMode(SWITCHPIN,INPUT);
  Serial.flush(); 
  Serial.begin(115200);
}

int num;
int r,g,b;
int led = 10;
int ks;

void loop() 
{
  // put your main code here, to run repeatedly:
  ks=digitalRead(A0);
//  ks = analogRead(A0);
  Serial.println(ks);
  if(ks)
  {
      r = random(0,255);
      g = random(0,255);
      b = random(0,255);
      for(num = 0; num < led; num++) 
      {
        pixels1.setPixelColor(num, pixels1.Color(r,g,b)); // Moderately bright green color.
      }
       pixels1.show(); // This sends the updated pixel color to the hardware
       
       //delay(s);
      while(digitalRead(A0) != 0);
      delay(200);      
  }
}

FAQ

版本历史记录

Version Date 新增/删除/修复