File: neurosky.py

package info (click to toggle)
minetest-mod-pycraft 0.22-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,744 kB
  • sloc: python: 79,282; makefile: 10
file content (52 lines) | stat: -rw-r--r-- 1,087 bytes parent folder | download | duplicates (3)
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
#
# Code under the MIT license by Alexander Pruss
#

from mc import *
import sys
import time
from NeuroPy.NeuroPy import NeuroPy

mc = Minecraft()

#
# the True argument is needed for a BrainFlex unit hacked to work
# at 57600 using
# http://www.instructables.com/id/Mindflex-EEG-with-raw-data-over-Bluetooth/
#
eeg = NeuroPy("COM11",57600,True)

meditation = len(sys.argv) > 1 and sys.argv[1].startswith("m")

up = 60
down = 40

def callback(a):
    mc.postToChat(a)
    if a > up:
       pos = mc.player.getPos()
       pos.y = pos.y + 1
       if mc.getBlock(pos.x,pos.y,pos.z) == AIR.id:
          mc.player.setPos(pos)
    elif a < down:
       pos = mc.player.getPos()
       pos.y = pos.y - 1
       if mc.getBlock(pos.x,pos.y,pos.z) == AIR.id:
          mc.player.setPos(pos)

if meditation:
    eeg.setCallBack("meditation", callback)
else:
    eeg.setCallBack("attention", callback)


mc.postToChat("Connecting to EEG")
eeg.start()

if meditation:
    mc.postToChat("To fly up, be meditative")
else:
    mc.postToChat("To fly up, be attentive")

while True:
    time.sleep(10)