p_p さん、こんにちは、
今後はできればソースコードは Code タグを使ってこんな風に掲示板の中に書いてください。
(余分な空行を取り除いたり、最後にあった establishContact() を前に持ってきたりしていますが、本質的には何も変えていません)
- コード: 全て選択
#define NUM 1
#define LIN_OUT 1 // use the lin output function
#define FFT_N 32 // set number of point fft
#include <FFT.h> // include the library
#include <TimerOne.h>
volatile int i; // index for data points
volatile int inByte;
const int voutPin = 0;
void timerIsr() {
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
i += 2;
}
void establishContact(){
while(Serial.available() <= 0){
Serial.println("0,0");
delay(300);
}
}
void setup(){
Serial.begin(115200);//シリアル速度
TIMSK0 = 0; // turn off timer0 for lower jitter
ADCSRA = 0xe5; // set the adc to free running mode
ADMUX = 0x40; // use adc0
DIDR0 = 0x01; // turn off the digital input for adc0
i = 0;
Timer1.initialize(1000); // set a timer of length 100 microseconds (10000Hz)
Timer1.attachInterrupt( timerIsr ); // attach the service routine here
inByte = 0;
establishContact();
}
void loop(){
while(i < FFT_N*2) {
}
cli(); // UDRE interrupt slows this way down on arduino1.0
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_lin(); // take the output of the fft
i = 0;
for (int l=0; l<FFT_N/2; l++){
Serial.print(fft_lin_out[l]); // send out the data
Serial.print(",");
}
Serial.println();
sei();
// R1の電圧を取得
int reading = analogRead(voutPin);
// AD値をmVに変換
float voltage = ((long)reading * 5000) / 1024;
// 電圧から電流を求める I=E/R (R=1200)
float microamp = (voltage * 1000) / 1200;
// 電流をlxに変換
//1.0mA/100lx
float lx = microamp / (1000 / 100);
int lx2 = (int)lx;
String lx3 = (String)lx2;
if(Serial.available() > 0){//processingにデータを送信
inByte = Serial.read();
for(int j = 0; j <NUM; j++){
Serial.print(lx3);
if(j < NUM - 1){
Serial.print(",");
}
else{
Serial.print('¥n');
}
}
}
}
「何でも作っちゃうかも」さんのページのスケッチも FFT の exampleもいずれも正しくコンパイルできるけれど、組み合わせると
sketch_jan20a:88: error: r28 cannot be used in asm here
sketch_jan20a:88: error: r29 cannot be used in asm here
というようなエラーが出るということですね。
ちょうど loop() の最後の } のあたりで怒られています。
おもしろいエラーですね
スケッチのどの部分がコンパイラの気に入らないかを突き止める必要がありますが、それには、先ずコンパイルできる状態までスケッチをコメントアウトして、その後、少しずつコメントを外していって、どこで叱られるかを調べてみるといいと思います。
とりあえず、loop() の中の 9 行めの i = 0 以降 loop の終わりまでをコメントアウトするとコンパイルできますね。
この状態からコメントを少しずつ外して、どこで、コンパイルエラーが出るかやってみてはいかがですか?
山口