-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArduinoMindwave.ino
57 lines (45 loc) · 1.92 KB
/
ArduinoMindwave.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "ThinkGearStreamParser.h"
#include <SoftwareSerial.h> //Software Serial Port
ThinkGearStreamParser parser;
#include <SoftwareSerial.h> // library for software serial
SoftwareSerial bluetoothSerial(5, 6); // RX, TX pins from the bluetooth module (here, we used a bluesmirf)
void setup(){
Serial.begin( 9600 ); // USB serial monitor to Arduino
bluetoothSerial.begin( 57600 ); // bluetooth serial to NeuroSky MindWave
THINKGEAR_initParser(&parser, handleDataValueFunc, NULL); // assign the handlers for the parser
Serial.flush();
}
void loop(){
while(!bluetoothSerial.available()) delay(4); // wait for a byte from the bluetooth connection
THINKGEAR_parseByte(&parser, bluetoothSerial.read()); // forward the byte to the stream parser
}
void handleDataValueFunc(unsigned char extendedCodeLevel, unsigned char code, unsigned char valueLength, const unsigned char *value) {
if( extendedCodeLevel == 0 ) {
switch( code ) {
/* [CODE]: ATTENTION eSense */
case( 0x04 ):
Serial.print( "Attention Level: " );
Serial.println( value[0] & 0xFF );
break;
/* [CODE]: MEDITATION eSense */
case( 0x05 ):
Serial.print( "Meditation Level: " );
Serial.println( value[0] & 0xFF );
break;
/* Other [CODE]s */
/*default:
Serial.print( "EXCODE level: ");
Serial.print( extendedCodeLevel );
Serial.print( " code: " );
Serial.print( code );
Serial.print( " vLength: " );
Serial.print( valueLength );
Serial.print( " value(s):" );
for( int i=0; i<valueLength; i++ ) {
Serial.print( value[i] & 0xFF );
Serial.print( " " );
}
Serial.println();*/
}
}
}