Skip to content

Commit 1b17ef4

Browse files
committed
Remove switch1prev
Smoothing can even be done with just one line! initialize switch1Smoothed for good measure.
1 parent d927254 commit 1b17ef4

1 file changed

Lines changed: 28 additions & 31 deletions

File tree

code/simple/simple.ino

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,29 @@
1-
int switch1;
2-
float switch1Smoothed;
3-
float switch1Prev;
4-
5-
void setup() {
6-
7-
Serial.begin(115200);
8-
9-
pinMode(12, INPUT_PULLUP);
10-
11-
}
12-
13-
void loop() {
14-
15-
switch1 = digitalRead(12); // read switch
16-
switch1 = switch1 * 100; // multiply by 100
17-
18-
// *** smoothing ***
19-
20-
switch1Smoothed = (switch1 * 0.05) + (switch1Prev * 0.95);
21-
22-
switch1Prev = switch1Smoothed;
23-
24-
// *** end of smoothing ***
25-
26-
Serial.print(switch1); // print to serial terminal/plotter
27-
Serial.print(" , ");
28-
Serial.println(switch1Smoothed);
29-
30-
delay(10); // run loop 100 times/second
31-
1+
int switch1;
2+
float switch1Smoothed = 0;
3+
4+
void setup() {
5+
6+
Serial.begin(115200);
7+
8+
pinMode(12, INPUT_PULLUP);
9+
10+
}
11+
12+
void loop() {
13+
14+
switch1 = digitalRead(12); // read switch
15+
switch1 = switch1 * 100; // multiply by 100
16+
17+
// *** smoothing ***
18+
19+
switch1Smoothed = (switch1 * 0.05) + (switch1Smoothed * 0.95);
20+
21+
// *** end of smoothing ***
22+
23+
Serial.print(switch1); // print to serial terminal/plotter
24+
Serial.print(" , ");
25+
Serial.println(switch1Smoothed);
26+
27+
delay(10); // run loop 100 times/second
28+
3229
}

0 commit comments

Comments
 (0)