두 스케치 합치기 방법..
페이지 정보
작성자 정윤진 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 작성일16-03-07 00:52 조회2,334회 댓글1건본문
boolean useSerial = true;
void sendSerial() {
if(useSerial) {
Serial.print(" ");
Serial.println(fft_log_out[j]);
}
}
void loop() {
......
if(Serial.available()) {
char a = Serial.read();
if(a == 'n')
useSerial = true;
else
useSerial = false;
}
......
}
이렇게 답변주셨는데요
/*
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() {
if(useSerial) {
Serial.print(" ");
Serial.println(fft_log_out[j]);
}
}
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(" ");
Serial.println(fft_log_out[j]);
delay(1000);
}
}
}
제가 합쳐본 건 인데요
이렇게 합치는 게 맞나요?ㅜㅜ 자꾸 빨간 부분에서
exit status 1
'j' was not declared in this scope
라고 오류뜨네요 ㅜㅜ
찾아보니까 선언부는 선언부끼리 void setup() 끼리 void loop()끼리 해라고 되어있는데 boolean useSerial = true; 랑 void sendSerial() 은 처음 보네요ㅜㅜ 이거는 어디다 넣어야 되는 거죠?
댓글목록
최고관리자님의 댓글

제가 잘못 적은듯 하네요. sendSerial() 함수를 아래처럼 바꿔보세요.
void sendSerial(float a) {
if(useSerial) {
Serial.print(" ");
Serial.println(a);
}
}
loop() - while() 반복문 안에 있는 아래 코드에 적용해야 합니다.
Serial.println(fft_log_out[j]);
==>
sendSerial(fft_log_out[j]);
fft_log_out[] 배열이 어떤 데이터 타입인지 모르겠네요. 라이브러리 코드를 보시고 데이터 타입은 맞춰주세요.