Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Arduino Brain Library - Brain Serial Test
- // Description: Grabs brain data from the serial RX pin and sends CSV out over the TX pin (Half duplex.)
- // More info: https://github.com/kitschpatrol/Arduino-Brain-Library
- // Author: Eric Mika, 2010 revised in 2014, Adapted for local SD Card Logging by Victor Frost
- const int chipSelect = 10;
- #include <Brain.h>
- #include <SdFat.h>
- SdFat sd;
- SdFile myFile;
- // Set up the brain parser, pass it the hardware serial object you want to listen on.
- Brain brain(Serial);
- void logEvent(const char *msg) {
- // create or open a file for append
- ofstream sdlog("LOGFILE.CSV", ios::out | ios::app);
- // append a line to the file
- sdlog << msg << endl;
- // check for errors
- if (!sdlog) sd.errorHalt("append failed");
- sdlog.close();
- }
- void setup() {
- pinMode(A0, OUTPUT);
- digitalWrite(A0, HIGH);
- // Start the hardware serial and get the SD Card ready.
- Serial.begin(9600);
- while (!Serial) {} // wait for Leonardo
- Serial.println("Starting Up");
- if (!sd.begin(chipSelect, SPI_HALF_SPEED)) sd.initErrorHalt();
- Serial.print("Logging Brain Activity");
- }
- void loop() {
- // Expect packets about once per second.
- // The .readCSV() function returns a string (well, char*) listing the most recent brain data, in the following format:
- // "signal strength, attention, meditation, delta, theta, low alpha, high alpha, low beta, high beta, low gamma, high gamma"
- // Also, log the data to the SDcard, since it's there.
- if (brain.update()) {
- Serial.println(brain.readErrors());
- Serial.println(brain.readCSV());
- logEvent(brain.readCSV());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement