-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBrainHacker.pde
71 lines (52 loc) · 1.59 KB
/
BrainHacker.pde
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
Delta waves 1⁄2Hz to 4Hz 2.2Hz deep unconscious, intuition and insight
Theta waves 4Hz to 8Hz 6.0Hz subconscious, creativity, deep relaxation
Alpha waves 8Hz to 13Hz 11.1Hz spacey and dreamy, receptive and passive
Beta waves 13Hz to 30Hz 14.4Hz conscious thought, external focus
*/
// uncomment to output current hertz to serial
// #define DEBUG
// http://code.google.com/p/arduino-tone/
#include <Tone.h>
// current brainwave-scoped freq
float hertz = 0;
// carrier frequency
float baseFreq = float(NOTE_C3);
// pin for analog speed control
int speedPot = 0;
// LED's are on these pins
int ledR = 8; // atmega pin 14, use 1K resistor
int ledL = 7; // atmega pin 13, use 1K resistor
// speakers are on these pins
int audR = 6; // atmega pin 11, use 1K resistor
int audL = 5; // atmega pin 12, use 1K resistor
int ledState = LOW; // ledState used to set the LED
long previousLEDMillis = 0; // will store last time LED was updated
Tone toneL;
Tone toneR;
void setup(){
#ifdef DEBUG
Serial.begin(9600);
#endif
pinMode(ledR, OUTPUT);
pinMode(ledL, OUTPUT);
toneL.begin(audL);
toneR.begin(audR);
}
void loop(){
// current brainwave-scoped freq, based on analog pot
hertz = float(map(analogRead(speedPot), 0, 1023, 5, 300)) / 10.00;
#ifdef DEBUG
Serial.println(hertz);
#endif
// AUDIO
toneL.play(baseFreq - (hertz/2.00));
toneR.play(baseFreq + (hertz/2.00));
// VISUAL
if ((millis() - previousLEDMillis) > (1000.00 / (hertz * 2.00))) {
previousLEDMillis = millis();
ledState = !ledState;
digitalWrite(ledL, ledState);
digitalWrite(ledR, !ledState);
}
}