|
1 | 1 | #if 1 // Change to 0 to disable this code (must enable ONE user*.cpp only!)
|
2 | 2 |
|
3 |
| -#include "globals.h" |
4 |
| - |
5 | 3 | // This file provides a crude way to "drop in" user code to the eyes,
|
6 | 4 | // allowing concurrent operations without having to maintain a bunch of
|
7 | 5 | // special derivatives of the eye code (which is still undergoing a lot
|
|
11 | 9 | // User globals can go here, recommend declaring as static, e.g.:
|
12 | 10 | // static int foo = 42;
|
13 | 11 |
|
14 |
| -const int sampleWindow = 400; // Sample window width in mS (50 mS = 20Hz) |
15 |
| - |
16 |
| -unsigned long end_millis= 0; // Start of sample window |
17 |
| - |
18 |
| -unsigned int left_max = 0; |
19 |
| -unsigned int left_min = 1024; |
20 |
| - |
21 |
| -unsigned int right_max = 0; |
22 |
| -unsigned int right_min = 1024; |
23 |
| - |
24 |
| -unsigned int sample_count = 0; |
25 |
| -unsigned int sample; |
26 |
| -unsigned int peakToPeak; |
27 |
| -double volts; |
28 |
| - |
29 |
| - |
30 |
| - |
31 | 12 | // Called once near the end of the setup() function. If your code requires
|
32 | 13 | // a lot of time to initialize, make periodic calls to yield() to keep the
|
33 | 14 | // USB mass storage filesystem alive.
|
34 | 15 | void user_setup(void) {
|
35 |
| - end_millis = millis() + sampleWindow; |
36 | 16 | }
|
37 | 17 |
|
38 | 18 | // Called periodically during eye animation. This is invoked in the
|
@@ -84,60 +64,6 @@ void user_loop(void) {
|
84 | 64 | }
|
85 | 65 | }
|
86 | 66 | */
|
87 |
| - |
88 |
| - |
89 |
| - if (millis() >= end_millis) { |
90 |
| - // process the current sampling |
91 |
| - if (left_max > left_min && right_max > right_min) { |
92 |
| - |
93 |
| - // process left |
94 |
| - peakToPeak = left_max - left_min; // max - min = peak-peak amplitude |
95 |
| - volts = (peakToPeak * 5.0) / 1024; // convert to volts |
96 |
| - Serial.print("Left: "); |
97 |
| - Serial.println(volts); |
98 |
| - if (volts > 1.0) { |
99 |
| - Serial.println("I hear you on the left"); |
100 |
| - } |
101 |
| - // process right |
102 |
| - peakToPeak = right_max - right_min; // max - min = peak-peak amplitude |
103 |
| - volts = (peakToPeak * 5.0) / 1024; // convert to volts |
104 |
| - Serial.print("Right "); |
105 |
| - Serial.println(volts); |
106 |
| - if (volts > 1.0) { |
107 |
| - Serial.println("I hear you on the right"); |
108 |
| - } |
109 |
| - } else { |
110 |
| - Serial.print("Not enough sampling: "); |
111 |
| - Serial.println(sample_count); |
112 |
| - } |
113 |
| - // and reset for the next sampling |
114 |
| - right_max = left_max = 0; |
115 |
| - right_min = left_min = 1024; |
116 |
| - end_millis = millis() + sampleWindow; |
117 |
| - sample_count = 0; |
118 |
| - } else { |
119 |
| - for (int i = 5; i > 0; i--) { |
120 |
| - sample_count++; |
121 |
| - // sample left |
122 |
| - sample = analogRead(2); |
123 |
| - if (sample < 1024) { // toss out spurious readings |
124 |
| - if (sample > left_max) { |
125 |
| - left_max = sample; // save just the max levels |
126 |
| - } else if (sample < left_min) { |
127 |
| - left_min = sample; // save just the min levels |
128 |
| - } |
129 |
| - } |
130 |
| - // sample right |
131 |
| - sample = analogRead(3); |
132 |
| - if (sample < 1024) { // toss out spurious readings |
133 |
| - if (sample > right_max) { |
134 |
| - right_max = sample; // save just the max levels |
135 |
| - } else if (sample < right_min) { |
136 |
| - right_min = sample; // save just the min levels |
137 |
| - } |
138 |
| - } |
139 |
| - } |
140 |
| - } |
141 | 67 | }
|
142 | 68 |
|
143 | 69 | #endif // 0
|
0 commit comments