Mental Block– tha code
Wednesday, December 30th, 2009Below is the code that was uploaded to each Arduino in each headset. Kudos to Eric for the noble task of commenting. It’s easier to read if you copy/paste into the Arduino IDE or another IDE like Eclipse.
Or you can just download the zipped file available right below.
ZIP!
// MENTAL BLOCK
// Parses packets from a Neurosky chip to collect EEG-derrived
// “attention” and “medidation” values.
// Uses these values to set the position of a polarized disk mounted
// on a servo.
#include <SoftwareServo.h>
#include <NewSoftSerial.h>
// Give the headset an ID. Useful for debugging over serial.
int id = 1;
// Set up the polarizer disk servo.
// Using the SoftwareServo library because I suspected the
// built-in library was conflicting with the NewSoftSerial
// library.
SoftwareServo servo;
int currentPos = 45; // Start halfway between the 0 – 90 degrees we care about.
int targetPos = 45; // The target tells the servo where it should move towards.
int servoPin = 9;
unsigned long lastMovement = 0; // Track time so we can move the servo at regular intervals without delay().
// Set up the simulator for brainless testing.
unsigned long lastSimulatedPacket = 0;
// NeuroSky Parser and Serial Communication.
(more…)


