我使用了带有arduino的msgeq7芯片,从所有连接在面包板上的音频插孔中分离音频。我有显示7个不同频率的代码,每个频率都有一个快速响亮的“响度”值。我想知道是否有人知道如何使用arduino中的数据在C#中创建图形频谱?只是一个7x6的网格,底部有绿色的点,顶部附近有红色的点,可以上下 float 以帮助可视化响度,这没什么复杂的。有人帮忙吗?
最佳答案
我不了解C#,但是您可以跳到处理https://processing.org/,它是基于Java构建的,但是很容易掌握。您可以使用处理与Arduino建立串行连接,并在它们之间发送数据,然后在您认为合适的情况下渲染处理中的数据。
示例Arduino代码:
void setup() {
Serial.begin(9600);
Serial.setTimeout(20);
delay(100);
}
void loop() {
//send data over serial port
Serial.println("Hello World");
delay(50);
}
处理代码:
import processing.serial.*;
Serial myPort;
String val;
void setup() {
smooth();
size(300, 350);
//you may have to mess around with the value in brackets to get the right on.
//Try printling out all values in Serial.list() and find your Arduino port name
String portName = Serial.list()[3];
println(portName);
myPort = new Serial(this, portName, 9600);
myPort.bufferUntil('\n');
}
void draw(){
//draw stuff
}
void serialEvent( Serial myPort) {
//put the incoming data into a String -
//the '\n' is our end delimiter indicating the end of a complete packet
val = myPort.readStringUntil('\n');
//make sure our data isn't empty before continuing
if (val != null) {
//trim whitespace and formatting characters (like carriage return)
val = trim(val);
println(val);
}
}
希望这可以帮助您入门。这些信息大部分来自Sparkfun Arduino处理教程https://learn.sparkfun.com/tutorials/connecting-arduino-to-processing
因此,如果您还有其他问题,请看一下。
关于c# - 具有C#或同等功能的Arduino音频频谱,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29651246/