0
  • 聊天消息
  • 系统消息
  • 评论与回复
登录后你可以
  • 下载海量资料
  • 学习在线课程
  • 观看技术视频
  • 写文章/发帖/加入社区
会员中心
创作中心

完善资料让更多小伙伴认识你,还能领取20积分哦,立即完善>

3天内不再提示

怎样用声音控制RGBLED的颜色

454398 来源:工程师吴畏 2019-07-31 11:06 次阅读

连接RGB LED的最长脚到Arduino。通过220欧姆电阻将其他支路连接到Arduino的引脚9,10和11,如下面的电路图所示。

怎样用声音控制RGBLED的颜色

如何运行程序

首先,粘贴在Arduino IDE中本文末尾为Arduino提供的代码并上传代码。

然后,您需要从Wekinator的示例页面下载草图。

下载MFCC的可执行文件(mel频率倒频谱系数)。我有一个64位操作系统,所以我从那里下载了“win64”。

下载后,解压缩并运行“.exe”文件。它将如下所示。现在您需要一个麦克风来为Wekinator提供输入。如果您已连接外接麦克风,请确保在计算机的声音设置中选择它。

您将需要另一个草图(“输出草图”) )从Wekinator获得输出。该草图在本文末尾给出。将其粘贴到新的处理窗口并运行草图。

现在打开Wekinator并进行如下图所示的设置。将输入设置为13,将输出设置为1.将类型设置为“所有动态时间扭曲”,使用3种手势类型,然后单击“下一步”。

现在按住output_1前面的“+”按钮并说“红色”。

然后按住output_2前面的“+”按钮并说“绿色”。

然后按住output_3前面的“+”按钮并说“蓝色”。

之后,单击“Train”,然后单击“Run”。现在,RGB LED的颜色将根据您说的颜色名称而改变。

Arduino代码

#include //Including the library that will help us in receiving and sending the values from processing

ValueReceiver《1》 receiver; /*Creating the receiver that will receive 1 value.

Put the number of values to synchronize in the brackets */

/* The below variable will be synchronized in the processing

and they should be same on both sides. */

int output;

// Initializing the pins for led‘s

int red_light_pin= 11;

int green_light_pin = 10;

int blue_light_pin = 9;

void setup()

{

/* Starting the serial communication because we are communicating with the

Processing through serial. The baudrate should be same as on the processing side. */

Serial.begin(19200);

pinMode(red_light_pin, OUTPUT);

pinMode(green_light_pin, OUTPUT);

pinMode(blue_light_pin, OUTPUT);

// Synchronizing the variable with the processing. The variable must be int type.

receiver.observe(output);

}

void loop()

{

// Receiving the output from the processing.

receiver.sync();

// Matching the received output to light up the RGB LED

if (output == 1)

{

RGB_color(255, 0, 0); // Red

}

else if (output == 2)

{

RGB_color(0, 255, 0); // Green

}

else if (output ==3)

{

RGB_color(0, 0, 255); // Blue

}

}

void RGB_color(int red_light_value, int green_light_value, int blue_light_value)

{

analogWrite(red_light_pin, red_light_value);

analogWrite(green_light_pin, green_light_value);

analogWrite(blue_light_pin, blue_light_value);

}

处理代码(输出草图)

import vsync.*; // Importing the library that will help us in sending and receiving the values from the Arduino

import processing.serial.*; // Importing the serial library

// Below libraries will connect and send, receive the values from wekinator

import oscP5.*;

import netP5.*;

// Creating the instances

OscP5 oscP5;

NetAddress dest;

ValueSender sender;

// This variable will be syncronized with the Arduino and it should be same on the Arduino side.

public int output;

void setup()

{

// Starting the serial communication, the baudrate and the com port should be same as on the Arduino side.

Serial serial = new Serial(this, “COM10”, 19200);

sender = new ValueSender(this, serial);

// Synchronizing the variable as on the Arduino side.

sender.observe(“output”);

// Starting the communication with wekinator. listen on port 12000, return messages on port 6448

oscP5 = new OscP5(this, 12000);

dest = new NetAddress(“127.0.0.1”, 6448);

}

//This is called automatically when OSC message is received

void oscEvent(OscMessage theOscMessage) {

if (theOscMessage.checkAddrPattern(“/output_1”)==true)

{

output = 1;

}

else if (theOscMessage.checkAddrPattern(“/output_2”)==true)

{

output = 2;

}

else if (theOscMessage.checkAddrPattern(“/output_3”) == true)

{

output = 3;

}

else

{

}

}

void draw()

{

// Nothing to be drawn for this example

}

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
  • led
    led
    +关注

    关注

    242

    文章

    23440

    浏览量

    664828
  • Arduino
    +关注

    关注

    188

    文章

    6478

    浏览量

    188396
收藏 人收藏

    评论

    相关推荐

    DLPC150采用I2C控制时,如何控制LED开关?如何控制显示的颜色

    在DLPC150 Programmer’s Guide文件只有对投影图像的控制命令,没有对灯光开关和颜色控制,请提供相关资料。
    发表于 02-21 10:41

    如何选择PCB颜色

    一、PCB颜色代表什么意思?   PCB颜色一般是指拿到一块PCB板时最直观看到的板子上的油色,PCB表面的颜色就是阻焊剂的颜色。PCB板染色颜料是一种硬化树脂,主体树脂是无色近透明的
    的头像 发表于 12-24 11:33 495次阅读

    TPA3001做音频信号的功放,输出的声音很沙哑是怎么回事?

    TPA3001做音频信号的功放,但是输出的声音很沙哑,之前公司用过这款芯片,我的电路图没有改变,但是声音不正常。我示波器测量所有的引脚的波形跟正常的一样,但是
    发表于 10-31 06:29

    请问TAS5706如何用硬件控制I2C?

    TAS5706 的Control Interface可以HW,SW。我想问问怎样用HW来控制呢?因为我一个板上预计8个TAS5706,MCU怎样去识别?
    发表于 10-23 08:33

    Tas2555声音通讯已实现,音量控制这个寄存器Speaker Control Register实现吗?

    Tas2555声音通讯已实现,音量控制这个寄存器Speaker Control Register实现吗?
    发表于 10-23 07:57

    多个TLV320AIC3254一路I2C总线对其配置可行吗?

    一片CPU3片TLV320AIC3254做音频处理,想用一路I2C总线对其配置可行吗? 地址好像是唯一的 0011000没法设置,手册中又提到可使用10位地址但是没找到说明怎样用,哪位大侠用过
    发表于 10-22 07:54

    如何用5509A产生一个白噪声,经AIC23播放出来然后再用AIC23采集这个声音

    怎样用5509A产生一个白噪声,经AIC23播放出来然后再用AIC23采集这个声音
    发表于 10-15 06:26

    探秘PCB板颜色:从外观到内涵的多重解读

    五花八门,从常见的绿色到罕见的红色、蓝色、黑色等,让人眼花缭乱。那么,这些不同颜色的PCB板到底有何用途?它们的背后又隐藏着怎样的奥秘呢?本文将为您一一揭晓。 PCB板颜色的由来和意义 首先,让我们来了解一下PCB板
    的头像 发表于 10-08 09:21 459次阅读

    怎样用自己的电脑远程公司的电脑

    随着远程办公和居家办公的普及,如何高效、安全地远程控制办公室电脑成为许多职场人士的需求。Splashtop作为一款专业的远程控制软件,提供了强大的功能,使用户能够随时随地访问和操作办公室的电脑,实现
    的头像 发表于 08-30 13:20 268次阅读
    <b class='flag-5'>怎样用</b>自己的电脑远程公司的电脑

    怎样用THS3201实现输出功率可调?

    怎样用THS3201实现输出功率可调?
    发表于 08-26 08:28

    OPA735加OPA333,怎样用TINA TI去仿真?

    当输入信号VG1从7.06V慢慢变化到7.22V时。 输出电压Vout的变化必须是接近线性变化的。我想知道我该怎样用TINA TI去仿真?怎样设置那个输入信号VG1才能达到我的目的。因为这个电压源好像
    发表于 08-02 08:39

    怎样用表测稳压管稳压值

    表是一种常用的电子测量工具,可以用来测量电压、电流、电阻等多种参数。在测量稳压管的稳压值时,我们可以使用万表的直流电压测量功能。以下是步骤和注意事项: 准备工具和材料 万表 稳压管 电源
    的头像 发表于 07-31 14:26 2159次阅读

    怎样用STM8L的PB3/TIM2_TRIG的引脚测量脉宽?

    怎样用STM8L的PB3/TIM2_TRIG的引脚测量脉宽?
    发表于 05-07 06:55

    stm32f100怎样用重映射功能?

    的是stm32f100c8t6b芯片,现在想用将PB1映射为TIM1_CH3N,在调用GPIO_PinAFConfig(GPIOB,GPIO_PinSource1,GPIO_AF_TIM1)时, GPIO_PinAFConfig和GPIO_AF_TIM1都没定义,stm32f100
    发表于 05-07 06:06

    STM32F412G-DISCO怎样用MX生成fatfs的代码?

    STM32F412G-DISCO怎样用MX生成fatfs的代码? SD卡例程能跑,但mx生成的代码不能正常运行,我生成代码后是不是还要配置一些东西?(我生成后只写了测试代码) 问题解决了,虽然我不知道我为什么不能直接使用mx生成的代码去操作sd卡,但我通过复制粘贴例程的代码完成了测试。
    发表于 03-12 08:15