데이터 타입....
페이지 정보
작성자 정윤진 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 작성일16-03-07 23:16 조회1,036회 댓글2건본문
제가 c언어에 대해 잘 모르는지라 어렵네요ㅜㅜ
/*
fft_adc.pde
guest openmusiclabs.com 8.18.12
example sketch for testing the fft library.
it takes in data on ADC0 (Analog0) and processes them
with the fft. the data is sent out over the serial
port at 115.2kb. there is a pure data patch for
visualizing the data.
*/
// do #defines BEFORE #includes
#define LOG_OUT 1 // use the log output function
#define FFT_N 256 // set to 256 point fft
#include <FFT2.h>
boolean useSerial = true;
void sendSerial(float a) {
if(useSerial) {
Serial.print(" ");
Serial.println(a);
}
}
void setup() {
Serial.begin(1200); // use the serial port
TIMSK0 = 0; // turn off timer0 for lower jitter - delay() and millis() killed
ADCSRA = 0xe5; // set the adc to free running mode
ADMUX = 0x40; // use adc0
DIDR0 = 0x01; // turn off the digital input for adc0
pinMode(A0, OUTPUT);
pinMode(12, INPUT);
Serial.println("reset!");
}
void loop() {
if(Serial.available()) {
char a = Serial.read();
if(a == 'n')
useSerial = true;
else
useSerial = false;
}
while(1) { // reduces jitter
cli(); // UDRE interrupt slows this way down on arduino1.0
for (int i = 0 ; i < 512 ; i += 2) { // save 256 samples
while(!(ADCSRA & 0x10)); // wait for adc to be ready
ADCSRA = 0xf5; // restart adc
byte m = ADCL; // fetch adc data
byte j = ADCH;
int k = (j << 8) | m; // form into an int
k -= 0x0200; // form into a signed int
k <<= 6; // form into a 16b signed int
fft_input[i] = k; // put real data into even bins
fft_input[i+1] = 0; // set odd bins to 0
}
// window data, then reorder, then run, then take output
fft_window(); // window the data for better frequency response
fft_reorder(); // reorder the data before doing the fft
fft_run(); // process the data in the fft
fft_mag_log(); // take the output of the fft
sei(); // turn interrupts back on
for (uint8_t j = 0; j < FFT_N/2; j++) {
Serial.print(" ");
sendSerial(fft_log_out[j]);
delay(1000);
}
}
}
답변주신대로 했으나 데이터타입이 먼지 몰라 그것빼고 수정했더니 컴파일 완료되고 시리얼모니터에 값들이 떴습니다. 그래도 여전히 잠시 사용하지 않는다는게 되지 않는 것 같네요 ㅜㅜ
1.
"PC에서 [n] 글자를 보내면 Serial 출력을 하고 이 외의 경우에는 출력하지 않도록 한 코드입니다."
이렇게 답변해주셨는데 그러면 시리얼 출력 하고 싶을 때는 n을 보내고 잠시 사용하지 않고 싶을 때는 p를 보내면 잠시 사용하지 않는다는 것입니까? 잠시사용하지 않는다는 말이 시리얼모니터에 값들이 나오지 않는다는 거죠? 그리고 잠시 사용하지 않는다는게 잠시 시리얼모니터가 쉬었다가 자기 알아서 다시 값들이 나오기 시작하는 건가요?
2. 데이터 타입이 먼지 궁금합니다. 일단 머부터 봐야할지 몰라 메모장 파일이랑 헤더파일 등 열어봤는데 도무지 모르겠더라구요 ㅜㅜ 복붙하려니 너무 많아서
http://wiki.openmusiclabs.com/wiki/ArduinoFFT 이 사이트에 있는 new 라이브러리를 다운로든 받아 사용했습니다. 데이터 타입 어디서 찾을 수 있는 건 가요?
항상 모르는게 많은 저의 글들을 읽어주셔서 감사합니다. ㅜㅜ 정말 너무 감사하고 죄송할 따름이네요ㅜㅜ
댓글목록
정윤진님의 댓글
정윤진 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 작성일글을 지우기는 아까워 삭제하지는 않겠습니다 ㅎ 이 질문에 대해 답변은 해주지 않으셔도 좋습니다ㅎ
최고관리자님의 댓글

1. if(Serial.available()) { ... } : 요 부분에 있는 코드가 PC에서 특정 문자를 보내면 그 값을 보고 메시지(FFT 값)를 출력할지 안할지 결정합니다. 'n'을 보내면 출력을 하고 다른 문자를 보내면 출력을 안하도록 설정합니다.
위 코드에서 sendSerial(float a) {...} 에서 PC의 시리얼 모니터에 출력되도록 데이터를 보내는데 사용자가 어떻게 설정했냐에 따라 문자를 보내기도하고 안보내기도 합니다.
프로그래밍 기초 부분 자료를 아래에서 참고하시고 좀 익혀 두시는 것이 추후 코드수정에 도움이 될 것 같습니다.
http://www.hardcopyworld.com/gnuboard5/bbs/board.php?bo_table=lecture_prog