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
    +关注

    关注

    244

    文章

    24724

    浏览量

    692514
  • Arduino
    +关注

    关注

    190

    文章

    6527

    浏览量

    197463
收藏 人收藏
加入交流群
微信小助手二维码

扫码添加小助手

加入工程师交流群

    评论

    相关推荐
    热点推荐

    MAX5486:立体声音量控制芯片的卓越之选

    MAX5486:立体声音量控制芯片的卓越之选 在音频应用的硬件设计领域,选择一款合适的音量控制芯片至关重要。今天我们要深入探讨的就是Maxim Integrated推出的MAX5486立体声音量控制
    的头像 发表于 04-18 11:45 196次阅读

    MAX5440:立体声音量控制的理想之选

    MAX5440:立体声音量控制的理想之选 在电子设备的音频系统中,音量和平衡控制是至关重要的功能。MAX5440作为一款专为立体声音量控制设计的芯片,凭借其独特的特性和广泛的应用场景,成为电子工程师
    的头像 发表于 04-18 10:00 202次阅读

    探索PGA2311立体声音频音量控制器:特性、应用与设计要点

    探索PGA2311立体声音频音量控制器:特性、应用与设计要点 在音频设备的设计领域中,高质量的音量控制是确保音频系统性能的关键因素之一。今天我们要深入探讨的主角——德州仪器(Texas
    的头像 发表于 02-04 11:20 458次阅读

    Texas Instruments PGA2320:高性能立体声音频音量控制芯片深度解析

    Texas Instruments PGA2320:高性能立体声音频音量控制芯片深度解析 在音频设备的设计领域,音频音量控制芯片的性能往往对整个系统的音质表现起着关键作用。今天,我们就来深入探讨
    的头像 发表于 02-03 11:30 524次阅读

    如何控制告警声音,或者实现长鸣告警?

    如何控制告警声音,或者实现长鸣告警?
    发表于 01-20 17:10

    字符串,数字控件如何控制背景颜色和前景字体颜色

    字符串,数字控件如何控制背景颜色和前景字体颜色
    发表于 01-20 15:12

    光纤线芯都是按照什么颜色排序的

    多次有朋友留言问到,光纤熔接颜色如何排序,这个在实际应用中还是比较多的,那么今天我们就不讲原理了,直接图文简单明了讲光纤熔接色谱,大家可以了解下。 一、常规排序 1、4芯的排序:蓝、橙、绿、棕
    的头像 发表于 12-19 11:02 2267次阅读

    如何在Keil中设置窗口标题颜色和背景颜色呢?

    如何在Keil中设置窗口标题颜色和背景颜色
    发表于 12-10 07:56

    如何进行声音定位?

    文章主要介绍了如何利用一种简单的TDOA算法进行声音点位,并使用数据采集卡进行声音定位的实验。
    的头像 发表于 09-23 15:47 2134次阅读
    如何进行<b class='flag-5'>声音</b>定位?

    【GUI设计】颜色对GUI的影响

    【LabviewGUI】颜色对GUI的影响 GUI最后一期了 后面回归主线
    发表于 08-26 04:51

    如何使用 M487 微控制器 (MCU) 通过 DAC 在 SD 卡上播放 WAV 文件声音

    使用 M487 微控制器 (MCU) 通过 DAC 在 SD 卡上播放 WAV 文件声音
    发表于 08-20 06:05

    声源定位模块-AR1105# 声源定位# 声音定位

    声音降噪
    深圳市声讯电子有限公司
    发布于 :2025年08月01日 16:01:09

    为什么现在的PCB大部分都是绿色?PCB 不同的颜色到底代表什么意思?

    一、PCB颜色代表什么意思?PCB颜色一般是指拿到一块PCB板时最直观看到的板子上的油色,PCB表面的颜色就是阻焊剂的颜色。PCB板染色颜料是一种硬化树脂,主体树脂是无色近透明的,绿色
    的头像 发表于 07-18 10:03 2132次阅读
    为什么现在的PCB大部分都是绿色?PCB 不同的<b class='flag-5'>颜色</b>到底代表什么意思?

    声音芯片有哪些类型和型号

    声音芯片其实一般业内称为语音芯片或者语音IC为主,声音芯片按功能类型来划分,分为OTP语音芯片、FLASH语音芯片、录音芯片、语音识别芯片。这其中语音识别芯片又可以叫做语音对话芯片或者语音控制芯片
    的头像 发表于 07-03 17:09 1130次阅读
    <b class='flag-5'>声音</b>芯片有哪些类型和型号

    新品上市丨阿童木CE系列颜色传感器

    导语在工业自动化领域,颜色检测的精度与效率直接影响产品品质与产线效能。阿童木智能科技推出CE系列高速智能型数字颜色传感器,以创新双模式检测逻辑与柔性化工业设计,为多行业提供稳定可靠的颜色检测解决方案
    的头像 发表于 06-11 16:11 1441次阅读
    新品上市丨阿童木CE系列<b class='flag-5'>颜色</b>传感器