Skip to content

Commit b8f12d1

Browse files
committed
Added EMG graphing option to sketch/python prg
1 parent b3ffa1a commit b8f12d1

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

.gitmodules

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
[submodule "arduino_connect"]
88
path = arduino_connect
99
url = https://github.com/BB121-LAB/arduino_connect
10+
branch = graph_option

diyemg_sketch/diyemg_sketch.ino

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2727
#define TRIGGER_LOW 150 // Low limit for trigger, adjust to change false-trigger rejection
2828
#define TRIGGER_WAIT_TIME_MS 50 // Delay between triggers, lower to increase speed of triggering
2929
typedef unsigned char BYTE;
30-
30+
BYTE channel_select = 0;
3131

3232
// Read analog input value and store in *level
3333
// optimized for high-performance
@@ -76,40 +76,48 @@ inline void __attribute__((optimize("O3"))) update_output(const int level) {
7676
void setup(void) {
7777
Serial.begin(115200);
7878
String mode;
79-
BYTE channel_select = 0;
8079

8180
// indicator
8281
pinMode(LED_BUILTIN, OUTPUT);
8382
digitalWrite(LED_BUILTIN, LOW);
8483

8584
// run until we get a valid input mode string from the computer
86-
while(true) {
85+
while(1) {
8786

8887
// Wait for input from the capture program to determine which
89-
while(!Serial.available()) {
88+
while(Serial.available() == 0) {}
89+
if(Serial.available()) {
9090
mode = Serial.readString(); // using C++ strings for input
9191
mode.trim();
92+
} else {
93+
continue;
9294
}
93-
95+
9496
// use input from serial to select ADC channel
9597
if(mode == "NORMAL") {
9698
channel_select = 0;
9799
break;
98100
}
99-
else if (mode == "WAVE") {
101+
else if(mode == "WAVE") {
100102
channel_select = 1;
101103
break;
102104
} else {
103105

104106
// input mode string was invalid, send error message to program,
105107
// clear buffers, and try again
106-
Serial.println("INVALID");
108+
Serial.print("INVALID \"");
109+
Serial.print(mode);
110+
Serial.println("\"");
111+
Serial.flush();
107112
while(!Serial.available()) {
108113
Serial.read();
109114
}
110115
continue;
111116
}
112-
}
117+
}
118+
119+
Serial.println("READY");
120+
Serial.flush();
113121

114122
// setup analog input A0 or A1 for operation
115123
// optimized for high-performance
@@ -123,6 +131,18 @@ void setup(void) {
123131
// optimized for high-performance
124132
void __attribute__((optimize("O3"), flatten)) loop(void) {
125133
int analog_level;
126-
update_reading(&analog_level);
127-
update_output(analog_level);
134+
char output_buffer[6];
135+
while(channel_select == 0) {
136+
update_reading(&analog_level);
137+
update_output(analog_level);
138+
}
139+
while(channel_select == 1) {
140+
while(Serial.available() == 0) {}
141+
while(Serial.available() > 0) {
142+
Serial.read();
143+
}
144+
update_reading(&analog_level);
145+
sprintf(output_buffer, "$%03d\n", analog_level);
146+
Serial.print(output_buffer);
147+
}
128148
}

0 commit comments

Comments
 (0)