I'd not heard of mindwave before and noted it wasn't shown in the IDE library manager. I searched and downloaded it from github and had a look. I'm not sure your original code would have compiled with that lib(maybe I'm missing something...) I tried to write something based on the lib. Sorry if I misunderstood or it's not what you're after. This compiles but whether it works or not, I don't know.
You'll have to tweak the xxx_LOW and xxx_HIGH definitions near the top to match attention levels to actions.
Nifty gizmo from the sounds of it.
//code trial 1
#include <Mindwave.h>
#define NUM_ATTNS 5
//
//
#define FWD_LOW 85
#define FWD_HIGH 100
//
#define RIGHT_LOW 60
#define RIGHT_HIGH 75
//
#define LEFT_LOW 40
#define LEFT_HIGH 55
//
#define BACK_LOW 20
#define BACK_HIGH 35
//
#define STOP_LOW 0
#define STOP_HIGH 15
//int constrainedInput = constrain(input, minimumValue, maximumValue);
const int left_motor_f = 13;
const int left_motor_r = 12;
const int right_motor_f = 11;
const int right_motor_r = 10;
bool
bmwNewData;
int
attention = 0;
Mindwave mindwave;
typedef struct
{
byte Command;
byte Low;
byte High;
}struct_MwAttentions;
struct_MwAttentions MwAttentions[NUM_ATTNS] =
{
{
.Command = 'F',
.Low = FWD_LOW,
.High = FWD_HIGH
},
{
.Command = 'R',
.Low = RIGHT_LOW,
.High = RIGHT_HIGH
},
{
.Command = 'L',
.Low = LEFT_LOW,
.High = LEFT_HIGH
},
{
.Command = 'B',
.Low = BACK_LOW,
.High = BACK_HIGH
},
{
.Command = 'S',
.Low = STOP_LOW,
.High = STOP_HIGH
}
};
void setup()
{
Serial.begin( MINDWAVE_BAUDRATE );
//mindwave.setDebug(true);
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
//Serial.begin(57600);
bmwNewData = false;
}//setup
void MindwaveCallback( void )
{
attention = mindwave.attention();
bmwNewData = true;
}//MindWaveCallback;
void loop()
{
mindwave.update( Serial, MindwaveCallback );
if( bmwNewData )
{
bmwNewData = false;
switch( AssignAttentionLevel() )
{
case 'F':
// ALL MOTORS GO FORWARTS
//Serial.print(attention);
digitalWrite(13, HIGH);
digitalWrite(12, LOW);
digitalWrite(11, HIGH);
digitalWrite(10, LOW);
break;
case 'B':
// ALL MOTORS GO BACKWORDS
//Serial.print(attention);
digitalWrite(13, LOW);
digitalWrite(12, HIGH);
digitalWrite(11, LOW);
digitalWrite(10, HIGH);
break;
case 'L':
// TURNS RIGHT
//Serial.print(attention);
digitalWrite(13, LOW);
digitalWrite(12, LOW);
digitalWrite(11, HIGH);
digitalWrite(10, LOW);
break;
case 'R':
// TURNS RIGHT
//Serial.print(attention);
digitalWrite(13, HIGH);
digitalWrite(12, LOW);
digitalWrite(11, LOW);
digitalWrite(10, LOW);
break;
case 'S':
// STOPS CAR
//Serial.print(attention);
digitalWrite(13, LOW);
digitalWrite(12, LOW);
digitalWrite(11, LOW);
digitalWrite(10, LOW);
break;
}//switch
}//if
}//loop
byte AssignAttentionLevel( void )
{
for( int i=0; i<NUM_ATTNS; i++ )
{
if( (attention >= MwAttentions[i].Low) && (attention >= MwAttentions[i].High) )
return( MwAttentions[i].Command );
}//for
//if no match found, command a stop
return ('S');
}//AssignAttentionLevel