-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwahball.ino
102 lines (87 loc) · 2.47 KB
/
wahball.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "accelerometer.h"
#include "expressionout.h"
#include "leds.h"
#include "pots.h"
#include "oscillator.h"
#define MODE_SELECT_PIN 3
#define MODE_WAHBALL 1
#define MODE_OSCILLATOR 2
#define MODE_TESTER 3
#define NUM_MODES 3 //I hate this, but itll do for now
byte curMode;
byte exp_vals[] = {0, 0, 0};
boolean DEBUG_MAP = false;
boolean DEBUG_POTS = false;
Accelerometer accel;
ExpressionOut expression;
Leds leds;
Pots pots;
Oscillator osc[NUM_OSCILLATORS];
void setup() {
Serial.begin(115200);
expression.setup();
accel.setup();
leds.setup();
pots.setup();
pinMode(MODE_SELECT_PIN, INPUT);
attachInterrupt(digitalPinToInterrupt(MODE_SELECT_PIN), advanceMode, CHANGE);
curMode = MODE_OSCILLATOR;
leds.setIndicatorsColor(CRGB::Purple);
}
void loop() {
accel.update();
pots.update();
if (curMode == MODE_WAHBALL) {
byte hue = map(accel.x(), -2000, 2000, 0, 255);
leds.setIndicatorsColor(CHSV(hue,255,100));
exp_vals[0] = map(accel.x(), -2000, 2000, 0, 255);
exp_vals[1] = map(accel.y(), -2000, 2000, 0, 255);
exp_vals[2] = map(accel.z(), -2000, 2000, 0, 255);
if (DEBUG_MAP == true)
{
printExpressionValues();
}
expression.update(exp_vals);
leds.setIndicatorsBrightness(exp_vals);
} else if (curMode == MODE_OSCILLATOR) {
for(int i=0; i<NUM_OSCILLATORS; i++) {
osc[i].setFrequency(map(pots.pot_vals[i], 0, 1024, MIN_FREQUENCY, MAX_FREQUENCY));
osc[i].setAmplitude(map(pots.pot_vals[i+3], 0, 1024, MIN_AMPLITUDE, MAX_AMPLITUDE));
exp_vals[i] = osc[i].getVal();
}
expression.update(exp_vals);
leds.setIndicatorsBrightness(exp_vals);
} else if (curMode == MODE_TESTER) {
exp_vals[0] = map(pots.pot_vals[0], 0, 1024, 0, 255);
exp_vals[1] = map(pots.pot_vals[1], 0, 1024, 0, 255);
exp_vals[2] = map(pots.pot_vals[2], 0, 1024, 0, 255);
expression.update(exp_vals);
leds.setIndicatorsBrightness(exp_vals);
if (DEBUG_POTS == true) {
pots.print();
delay(100);
}
}
}
void printExpressionValues() {
for (byte i = 0; i < 3; i++) {
Serial.print("E");
Serial.print(i);
Serial.print(": ");
Serial.print(exp_vals[i]);
Serial.println("\t");
}
}
void advanceMode() {
curMode++;
if (curMode > NUM_MODES) {
curMode = 1;
}
if(curMode == MODE_TESTER) {
leds.setIndicatorsColor(CRGB::Red);
} else if(curMode == MODE_OSCILLATOR) {
leds.setIndicatorsColor(CRGB::Purple);
}
Serial.print("switching to mode ");
Serial.println(curMode);
}