aa develop

開発と成長

Museで取得した脳波に基づき,ArduinoでLEDを光らせる

脳波ヘッドバンドのMuseで脳波から集中度を所得し,その値をProcessingでArduinoに送ってLEDの明るさを変化させる. MuseはPCとBluetooth接続し,ターミナルから以下のコマンドを実行する.

$ muse-io --device Muse-XXXX --osc osc.udp://localhost:5000

LEDはArduinoのGRDとD13に接続する.

Processing

/**
*
* Before running this program,you need to launch 
* MuseIO by below command in your terminal.
* 
* $ muse-io --device Muse-XXXX --osc osc.udp://localhost:5000
*/


import processing.serial.*;
import oscP5.*;

OscP5 oscP5;
Serial serial;

float concentration = 0;

void setup(){
  size(300, 300);
  noStroke();
  fill(255, 20, 147);
  oscP5 = new OscP5(this, 5000);
  serial = new Serial(this, "/dev/tty.usbmodem1411", 9600);
}

void draw(){
  background(64);
  float radious = map(concentration, 0, 1, 50, 300);
  ellipse(width/2, height/2, radious, radious);
  println(concentration);
  serial.write(int(map(concentration, 0, 1, 0, 255)));
}

void oscEvent(OscMessage msg){
  if(msg.checkAddrPattern("/muse/elements/experimental/concentration")){
    concentration = msg.get(0).floatValue();  
  }
}
Arduino


int v = 0;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(13, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  if(Serial.available() > 0){
    v = Serial.read();
  }
  int ms = map(v, 0, 255, 0, 10);
  digitalWrite(13, HIGH);
  delay(ms);
  digitalWrite(13, LOW);
  delay(10 - ms);
}

Arduino/signal_from_muse_to_arduino_via_processing at master · aa-debdeb/Arduino