データロガーのスケッチがエラーに
Posted: 2014年9月29日(月) 18:41
皆様、お願い致します。
SDカードに変化が有った時にPINの状態を、このようなデータを記録していきたいのです。
2014/09/19 20:18:10 0000 0000 0100 0000 0000
接続するピンの数は16系統でデジタル10アナログ6を使っています。
おしえてgooなどのサイトで質問しながらスケッチしてきましたが、どうにも進まなくなってしまいました。
現在「Leonardo」+「Adafruit Data Logger Shield」を使っています。
デジタルピン10, 11, 12, 13はSDカードとして使うそうです。
またSD.hは Adafruit 用のものを使います。
今、出ているエラーです
Datalogger_TIME_osiete6.ino: In function 'void loop()':
Datalogger_TIME_osiete6:47: error: 'ChgFlag' was not declared in this scope
Datalogger_TIME_osiete6:48: error: 'i' was not declared in this scope
カッコの位置や変数の宣言だと思うのですが・・・
スケッチ全体を張り付けるのでチェックしていただければ幸いです。
よろしくお願い致します。
#include <SPI.h>
#include <SD.h>
#include <Wire.h>
#include <RTClib.h> // Credit: Adafruit
RTC_DS1307 RTC;
#define DPINMAX 16
int Digitalpin [DPINMAX] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 14, 15, 16, 17, 18, 19};
int val = 0;// 入力ピンの状態がこの変数(val)に記憶される
int old_val = 0;// valの前の値を保存しておく変数
const int chipSelect = 10;// Adafruit のSDシールドは 10
void setup(){
// see if the card is present and can be initialized:
if (!SD.begin(10, 11, 12, 13)) {//データロガーシールド用スケッチ
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
Serial.println("card initialized.");
Serial.begin(9600); // Open serial communications and wait for port to open:
// Instantiate the RTC
Wire.begin();
RTC.begin();
// Check if the RTC is running.
if (! RTC.isrunning()) {
Serial.println("RTC is NOT running");
}
// This section grabs the current datetime and compares it to
// the compilation time. If necessary, the RTC is updated.
DateTime now = RTC.now();
DateTime compiled = DateTime(__DATE__, __TIME__);
if (now.unixtime() < compiled.unixtime()) {
Serial.println("RTC is older than compile time! Updating");
RTC.adjust(DateTime(__DATE__, __TIME__));
}
Serial.println("Setup complete.");
}
void loop()
{
DateTime now = RTC.now();
File dataFile = SD.open("datalog.txt", FILE_WRITE);
ChgFlag = 0;/* 変化あったか確認するためのフラグをクリア */
for(i=0;i<DPINMAX;i++) {
val = digitalRead(Digitalpin);
old_val = digitalRead(Digitalpin);
if(val != old_val) {
ChgFlag = 1; /* 前回から変化ありました*/
old_val = val; /* 今回の値に更新します */
}
}
if(ChgFlag != 0){ /* 変化あったらからSDに書き出すよ~ */
}
for(i=0;i<(sizeof(old_val)/sizeof(int));i++) {
dataFile.print(old_val);
if((i % 4) == 0)
dataFile.print(" ");
}
dataFile.println(); /* 最後に改行追加 */
dataFile.close();
}
SDカードに変化が有った時にPINの状態を、このようなデータを記録していきたいのです。
2014/09/19 20:18:10 0000 0000 0100 0000 0000
接続するピンの数は16系統でデジタル10アナログ6を使っています。
おしえてgooなどのサイトで質問しながらスケッチしてきましたが、どうにも進まなくなってしまいました。
現在「Leonardo」+「Adafruit Data Logger Shield」を使っています。
デジタルピン10, 11, 12, 13はSDカードとして使うそうです。
またSD.hは Adafruit 用のものを使います。
今、出ているエラーです
Datalogger_TIME_osiete6.ino: In function 'void loop()':
Datalogger_TIME_osiete6:47: error: 'ChgFlag' was not declared in this scope
Datalogger_TIME_osiete6:48: error: 'i' was not declared in this scope
カッコの位置や変数の宣言だと思うのですが・・・
スケッチ全体を張り付けるのでチェックしていただければ幸いです。
よろしくお願い致します。
#include <SPI.h>
#include <SD.h>
#include <Wire.h>
#include <RTClib.h> // Credit: Adafruit
RTC_DS1307 RTC;
#define DPINMAX 16
int Digitalpin [DPINMAX] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 14, 15, 16, 17, 18, 19};
int val = 0;// 入力ピンの状態がこの変数(val)に記憶される
int old_val = 0;// valの前の値を保存しておく変数
const int chipSelect = 10;// Adafruit のSDシールドは 10
void setup(){
// see if the card is present and can be initialized:
if (!SD.begin(10, 11, 12, 13)) {//データロガーシールド用スケッチ
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
Serial.println("card initialized.");
Serial.begin(9600); // Open serial communications and wait for port to open:
// Instantiate the RTC
Wire.begin();
RTC.begin();
// Check if the RTC is running.
if (! RTC.isrunning()) {
Serial.println("RTC is NOT running");
}
// This section grabs the current datetime and compares it to
// the compilation time. If necessary, the RTC is updated.
DateTime now = RTC.now();
DateTime compiled = DateTime(__DATE__, __TIME__);
if (now.unixtime() < compiled.unixtime()) {
Serial.println("RTC is older than compile time! Updating");
RTC.adjust(DateTime(__DATE__, __TIME__));
}
Serial.println("Setup complete.");
}
void loop()
{
DateTime now = RTC.now();
File dataFile = SD.open("datalog.txt", FILE_WRITE);
ChgFlag = 0;/* 変化あったか確認するためのフラグをクリア */
for(i=0;i<DPINMAX;i++) {
val = digitalRead(Digitalpin);
old_val = digitalRead(Digitalpin);
if(val != old_val) {
ChgFlag = 1; /* 前回から変化ありました*/
old_val = val; /* 今回の値に更新します */
}
}
if(ChgFlag != 0){ /* 変化あったらからSDに書き出すよ~ */
}
for(i=0;i<(sizeof(old_val)/sizeof(int));i++) {
dataFile.print(old_val);
if((i % 4) == 0)
dataFile.print(" ");
}
dataFile.println(); /* 最後に改行追加 */
dataFile.close();
}