File tree Expand file tree Collapse file tree 1 file changed +37
-4
lines changed Expand file tree Collapse file tree 1 file changed +37
-4
lines changed Original file line number Diff line number Diff line change @@ -75,14 +75,47 @@ inline void __attribute__((optimize("O3"))) update_output(const int level) {
75
75
76
76
void setup (void ) {
77
77
Serial.begin (115200 );
78
-
78
+ String mode;
79
+ BYTE channel_select = 0 ;
80
+
79
81
// indicator
80
82
pinMode (LED_BUILTIN, OUTPUT);
81
83
digitalWrite (LED_BUILTIN, LOW);
82
-
83
- // setup analog input A0 for operation
84
+
85
+ // run until we get a valid input mode string from the computer
86
+ while (true ) {
87
+
88
+ // Wait for input from the capture program to determine which
89
+ while (!Serial.available ()) {
90
+ mode = Serial.readString (); // using C++ strings for input
91
+ mode.trim ();
92
+ }
93
+
94
+ // use input from serial to select ADC channel
95
+ if (mode == " NORMAL" ) {
96
+ channel_select = 0 ;
97
+ break ;
98
+ }
99
+ else if (mode == " WAVE" ) {
100
+ channel_select = 1 ;
101
+ break ;
102
+ } else {
103
+
104
+ // input mode string was invalid, send error message to program,
105
+ // clear buffers, and try again
106
+ Serial.println (" INVALID" );
107
+ while (!Serial.available ()) {
108
+ Serial.read ();
109
+ }
110
+ continue ;
111
+ }
112
+ }
113
+
114
+ // setup analog input A0 or A1 for operation
84
115
// optimized for high-performance
85
- ADMUX = (1 << REFS0);
116
+ // channel_select determines which ADC channel is active
117
+ // 0 = A0, 1 = A1
118
+ ADMUX = (1 << REFS0) | channel_select;
86
119
ADCSRA = 0x82 ;
87
120
}
88
121
You can’t perform that action at this time.
0 commit comments