Can't update data through the Loop

Hello,

I'm currently working on an EEG system using the Arduino. The purpose of the system is to vibrate a vibrator for .1 seconds, wait .5 seconds, and then vibrate again for .1 seconds. However from the start I want it to read the EEG (Serial.println(brain.readCSV()); Serial.println(brain.readErrors()):wink: every .1 seconds from the start.

The problem is that it only takes one sample and just repeats it throughout the process until it cycles, instead of continuously updating through the loop.

How can I get it to continuously read the new data while the entire system is operating.

#include "Brain.h"
#include <SPI.h>
#include <Wire.h>

int n=0;
int m=0;

// Set up the brain parser, pass it the hardware serial object you want to listen on.
Brain brain(Serial);
int vib = 5;

void setup() {
  // Start the hardware serial.
  Serial.begin(9600);
  pinMode(vib, OUTPUT);
}

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"  
  if (brain.update()) {
          Serial.println(brain.readCSV());
      Serial.println(brain.readErrors());
  
if(brain.readSignalQuality() == 0) {     
 // Vibrate
  digitalWrite(vib,HIGH);
      Serial.println(brain.readCSV());
      Serial.println(brain.readErrors());
   delay(100);
while (n<500){
    n=n+100;
    digitalWrite(vib,LOW);
    Serial.println(brain.readCSV());
    Serial.println(brain.readErrors());
    Serial.println(n);
    delay(100);
  }
  digitalWrite(vib,HIGH);
  Serial.println(brain.readCSV());
  Serial.println(brain.readErrors());
   delay(100);
while (m<10000){
    m=m+100;
    digitalWrite(vib,LOW);
    Serial.println(brain.readCSV());
    Serial.println(brain.readErrors());
    Serial.println(m);
    delay(100);
  }
  n=0;
  m=0;
    }
  }
}

What you will want to do is use the millis() function to do your timing instead of the delay() function. Here is a tutorial on how to do that: BlinkWithoutDelay

Nothing can happen during your delays. Nothing can happen when you flood the serial.print with data. Fix both and try it.

Paul

Can you please provide a link to where you got the Brain library ?