www.久久久久|狼友网站av天堂|精品国产无码a片|一级av色欲av|91在线播放视频|亚洲无码主播在线|国产精品草久在线|明星AV网站在线|污污内射久久一区|婷婷综合视频网站

當(dāng)前位置:首頁 > 工業(yè)控制 > 電路設(shè)計項目集錦
[導(dǎo)讀]在我的數(shù)字電路課程中,我們的任務(wù)是創(chuàng)建一個項目提案,主題可以自由選擇,然后將課程中學(xué)到的知識應(yīng)用到最終的項目中,該項目必須在虛擬電路模擬器中實現(xiàn)。我選擇使用Wokwi,一個我在這個項目之前從未使用過的平臺。經(jīng)過一番思考,我決定制作一個音頻頻譜可視化器作為我自己辦公桌的裝飾品。經(jīng)過一番研究,我發(fā)現(xiàn)這個想法已經(jīng)被做過很多次了,因此不是很原創(chuàng)。因此,我決定以其中一個項目為基礎(chǔ),為交互式桌面裝飾構(gòu)建額外的功能。

為我大學(xué)的數(shù)字電路課程做的項目,目的是有一些很酷的東西放在你的桌子上。

在我的數(shù)字電路課程中,我們的任務(wù)是創(chuàng)建一個項目提案,主題可以自由選擇,然后將課程中學(xué)到的知識應(yīng)用到最終的項目中,該項目必須在虛擬電路模擬器中實現(xiàn)。我選擇使用Wokwi,一個我在這個項目之前從未使用過的平臺。經(jīng)過一番思考,我決定制作一個音頻頻譜可視化器作為我自己辦公桌的裝飾品。經(jīng)過一番研究,我發(fā)現(xiàn)這個想法已經(jīng)被做過很多次了,因此不是很原創(chuàng)。因此,我決定以其中一個項目為基礎(chǔ),為交互式桌面裝飾構(gòu)建額外的功能。

項目:

當(dāng)我開始做這個項目時,我意識到我所選擇的項目和我在提案中概述的項目與我所選擇的平臺不兼容。這是一個物理項目,使用了Wokwi上沒有的庫,而且我無法導(dǎo)入它們,因為我使用的是該平臺的免費版本。我找了另一個項目作為基礎(chǔ),一個利用LED矩陣,但我找不到任何。我只找到了使用顯示器的類似項目。所以,我必須從頭開始,學(xué)習(xí)LED矩陣是如何工作的,它的庫,以及如何操縱它。我開始創(chuàng)建列,然后使它們上下移動,最后使它們彼此獨立。完成這一部分后,我開始研究音頻頻譜可視化是如何工作的,并從類似的項目中尋求靈感。我選擇了被稱贊的項目,因為它的代碼看起來更可讀,也就是在那時,我了解到fix_fft庫的存在,它救了我的命。使用庫,檢查文檔,并了解我受到啟發(fā)的項目如何工作,我逐漸更改了我在LED矩陣中創(chuàng)建的列。

遇到的困難:

最初的想法是使用蜂鳴器和麥克風(fēng)來顯示移動的音頻頻譜。然而,該平臺的麥克風(fēng)傳感器缺乏文檔,似乎功能不全,因為它只產(chǎn)生噪音,而不檢測蜂鳴器發(fā)出的聲音。在教授的指導(dǎo)下,我用一個簡單的電位器代替了蜂鳴器和麥克風(fēng),這個電位器可以模擬麥克風(fēng)檢測蜂鳴器聲音的輸出。我花了幾個小時重新組織項目,并添加了最后的潤色。但它是這樣的:在最后期限內(nèi)完成,比我最初計劃的項目范圍付出了更多的努力和工作。

代碼

#include

#include "fix_fft.h"

#define CLK_PIN 13

#define DATA_PIN 11

#define CS_PIN 10

#define inAudio A0

#define inPot A1

char re[128], im[128];

void modLine(int line, int val1, int val2, int val3, int val4){

digitalWrite(CS_PIN, LOW);

/* The standard LED matrix is 8x8;

For some reason, Wokwi uses an 8x32 matrix, so it's as if there are 4 modules connected together.

Therefore, for every 8 columns, a new HEX value must be sent to control the next module.

It's not possible to use a loop or skip modules; each module must be updated every frame,

or the last modules will be treated as non-existent.*/

SPI.transfer(line);

SPI.transfer(val4); // Last 8x8 module

SPI.transfer(line);

SPI.transfer(val3);

SPI.transfer(line);

SPI.transfer(val2);

SPI.transfer(line);

SPI.transfer(val1); // First 8x8 module

digitalWrite(CS_PIN, HIGH);

}

void setup(){

Serial.begin(6900);

pinMode(CS_PIN, OUTPUT);

SPI.begin();

}

void loop(){

int i=0, j=0;

/*This is a conversion of the values I have to apply to the FFT;

FFT: "Fast Fourier Transform";

Basically, it's mathematics (i.e., magic) that converts a signal into sound frequency.*/

//Serial.println(analogRead(inAudio)); //Uncomment accordantly to visualize the frequency input

//Serial.println(analogRead(inPot)); //Uncomment accordantly to visualize the frequency input

for (i = 0; i < 128; i++){

int mic1 = analogRead(inPot); //Potentiometer so we can emulate a microphone

re[i] = mic1 / 4 - 128; // AnalogRead returns value from 0 to 1023, here, we convert it to go from -128 to 127

im[i] = 0; // Imaginary part of the FFT

}

/* Eu vou dar um BEIJO em quem criou essa bib.h*/

fix_fft(re, im, 7, 0);

int height[4] = {0, 0, 0, 0}; //Height for every column

static int prevHeight[4] = {0, 0, 0, 0}; //This for the climb/drop animation of the column of LEDS

int magnitude=0;

for (j = i * 16; j < (i + 1) * 16; j++){ //Considers only the first 64 frequencies

magnitude = magnitude + sqrt(re[j] * re[j] + im[i] * im[i]);

}

//Serial.println(magnitude); //Uncomment to see the resulting magnitude

for (i = 0; i < 4; i++) {

height[i] = map(magnitude * (i + 1) / 4, 0, 2080, 0, 8); //Divides and maps the frequency into 4 major groups that go from 0 to 8 each

height[i] = constrain(height[i], 0, 8); // Guarantees that the value is between 0 e 8

//Serial.println(height[i]); //Uncomment to see the height of each column

}

for (int i = 0; i < 4; i++) { //Here were doing the animation previously mentioned

while (prevHeight[i] != height[i]) {

if (prevHeight[i] < height[i]) {

prevHeight[i]++;

} else {

prevHeight[i]--;

}

for (int j = 0; j < 8; j++) {

int line = 8 - j;

int val1 = (j < prevHeight[0]) ? 0x7E : 0x00;

int val2 = (j < prevHeight[1]) ? 0x7E : 0x00;

int val3 = (j < prevHeight[2]) ? 0x7E : 0x00;

int val4 = (j < prevHeight[3]) ? 0x7E : 0x00;

modLine(line, val1, val2, val3, val4);

}

delay(10); //Slows down the process so that the animation is smoother

}

}

}

本文編譯自hackster.io

本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點,本站亦不保證或承諾內(nèi)容真實性等。需要轉(zhuǎn)載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請及時聯(lián)系本站刪除。
換一批
延伸閱讀
關(guān)閉