Skip to content

Commit 70bec96

Browse files
committed
Updating/adding example sketches to demonstrate each Devlpr method.
1 parent b304f7b commit 70bec96

8 files changed

Lines changed: 134 additions & 25 deletions

File tree

examples/flex_detection/flex_detection.ino

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
1-
#include "Devlpr.h"
1+
#include <libdevlpr.h>
22

3-
Devlpr devlpr;
4-
5-
void printEMG(Devlpr *d) {
6-
int result = d->windowPeakToPeakAmplitude();
7-
Serial.print("0 1024 ");
8-
Serial.println(result);
9-
}
3+
// create a DEVLPR object with the pin we have connected on the shield
4+
// can create multiple for different pins if stacking shields
5+
Devlpr devlpr(A0);
106

117
void writeFlex(Devlpr *d) {
8+
// since this function is called when a flex is detected, just print
129
Serial.println("FLEX");
1310
}
1411

1512
void setup() {
13+
// prepare Serial for printing to the monitor
1614
Serial.begin(2000000);
17-
// add our print function to our DEVLPR schedule
18-
// try to run once every 1ms
19-
devlpr.scheduleFunction(printEMG, 1);
20-
//devlpr.setFlexCallback(writeFlex);
15+
// set the callback for flex detection
16+
// flex detection is based on a multiple of peak-to-peak amplitude
17+
// here we set the mutliple to be 1.7x baseline and a cooldown of 300ms
18+
devlpr.setFlexCallback(writeFlex, 1.7, 300);
2119
}
2220

2321
void loop() {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <libdevlpr.h>
2+
3+
// create a DEVLPR object with the pin we have connected on the shield
4+
// can create multiple for different pins if stacking shields
5+
Devlpr devlpr(A0);
6+
7+
void printAvg(Devlpr *d) {
8+
// first grab the most recent window average of EMG values sampled
9+
// this is effectively a low-pass filter
10+
int result = d->windowAvg();
11+
// we will print three values each time: 0, 1024, and the measurement
12+
// the 0 and 1024 simply give us a top and bottom line in the plotter
13+
Serial.print("0 1024 ");
14+
Serial.println(result);
15+
}
16+
17+
void setup() {
18+
// prepare Serial for printing to the plotter
19+
Serial.begin(2000000);
20+
// add a printing function as a scheduled callback for our Devlpr
21+
// here we set the function to be called every 1ms
22+
devlpr.scheduleFunction(printAvg, 1);
23+
}
24+
25+
void loop() {
26+
// let the DEVLPR library do its job
27+
devlpr.tick();
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <libdevlpr.h>
2+
3+
// create a DEVLPR object with the pin we have connected on the shield
4+
// can create multiple for different pins if stacking shields
5+
Devlpr devlpr(A0);
6+
7+
void printEMG(Devlpr *d) {
8+
// first grab the most recent raw EMG value sampled and then centered
9+
// this method subtracts a window average to roughly center around 0
10+
int result = d->lastValueCentered();
11+
// we will print three values each time: -1024, 1024, and the measurement
12+
// the -1024 and 1024 simply give us a top and bottom line in the plotter
13+
Serial.print("-1024 1024 ");
14+
Serial.println(result);
15+
}
16+
17+
void setup() {
18+
// prepare Serial for printing to the plotter
19+
Serial.begin(2000000);
20+
// add a printing function as a scheduled callback for our Devlpr
21+
// here we set the function to be called every 1ms
22+
devlpr.scheduleFunction(printEMG, 1);
23+
}
24+
25+
void loop() {
26+
// let the DEVLPR library do its job
27+
devlpr.tick();
28+
}

examples/plot_peak/plot_peak.ino

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <libdevlpr.h>
2+
3+
// create a DEVLPR object with the pin we have connected on the shield
4+
// can create multiple for different pins if stacking shields
5+
Devlpr devlpr(A0);
6+
7+
void printPeak(Devlpr *d) {
8+
// first grab the peak amplitude (max) as measured in the current window
9+
int result = d->windowPeakAmplitude();
10+
// we will print three values each time: 0, 1024, and the measurement
11+
// the 0 and 1024 simply give us a top and bottom line in the plotter
12+
Serial.print("0 1024 ");
13+
Serial.println(result);
14+
}
15+
16+
void setup() {
17+
// prepare Serial for printing to the plotter
18+
Serial.begin(2000000);
19+
// add a printing function as a scheduled callback for our Devlpr
20+
// here we set the function to be called every 1ms
21+
devlpr.scheduleFunction(printPeak, 1);
22+
}
23+
24+
void loop() {
25+
// let the DEVLPR library do its job
26+
devlpr.tick();
27+
}

examples/plot_peak_to_peak/plot_peak_to_peak.ino

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
1-
#include "Devlpr.h"
1+
#include <libdevlpr.h>
22

3-
Devlpr devlpr;
3+
// create a DEVLPR object with the pin we have connected on the shield
4+
// can create multiple for different pins if stacking shields
5+
Devlpr devlpr(A0);
46

5-
void printEMG(Devlpr *d) {
7+
void printP2P(Devlpr *d) {
8+
// first grab the peak-to-peak amplitude (max-min) as measured in the current window
69
int result = d->windowPeakToPeakAmplitude();
10+
// we will print three values each time: 0, 1024, and the measurement
11+
// the 0 and 1024 simply give us a top and bottom line in the plotter
712
Serial.print("0 1024 ");
813
Serial.println(result);
914
}
1015

11-
void writeFlex(Devlpr *d) {
12-
Serial.println("FLEX");
13-
}
14-
1516
void setup() {
17+
// prepare Serial for printing to the plotter
1618
Serial.begin(2000000);
17-
// add our print function to our DEVLPR schedule
18-
// try to run once every 1ms
19-
devlpr.scheduleFunction(printEMG, 1);
20-
//devlpr.setFlexCallback(writeFlex);
19+
// add a printing function as a scheduled callback for our Devlpr
20+
// here we set the function to be called every 1ms
21+
devlpr.scheduleFunction(printP2P, 1);
2122
}
2223

2324
void loop() {
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <libdevlpr.h>
2+
3+
// create a DEVLPR object with the pin we have connected on the shield
4+
// can create multiple for different pins if stacking shields
5+
Devlpr devlpr(A0);
6+
7+
void printEMG(Devlpr *d) {
8+
// first grab the most recent raw EMG value sampled
9+
int result = d->lastValue();
10+
// we will print three values each time: 0, 1024, and the measurement
11+
// the 0 and 1024 simply give us a top and bottom line in the plotter
12+
Serial.print("0 1024 ");
13+
Serial.println(result);
14+
}
15+
16+
void setup() {
17+
// prepare Serial for printing to the plotter
18+
Serial.begin(2000000);
19+
// add a printing function as a scheduled callback for our Devlpr
20+
// here we set the function to be called every 1ms
21+
devlpr.scheduleFunction(printEMG, 1);
22+
}
23+
24+
void loop() {
25+
// let the DEVLPR library do its job
26+
devlpr.tick();
27+
}

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Libdevlpr
2-
version=0.1.2
2+
version=0.1.3
33
author=Finn Kuusisto <finn@getfantm.com>, Ezra Boley <ezra@getfantm.com>
44
maintainer=Finn Kuusisto <finn@getfantm.com>
55
sentence=A library that makes using the FANTM DEVLPR shield easier.

src/libdevlpr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef libdevlpr_h
22
#define libdevlpr_h
33

4-
#define LIBDEVLPR_VERSION "0.1.2"
4+
#define LIBDEVLPR_VERSION "0.1.3"
55

66
#include "Devlpr.h"
77

0 commit comments

Comments
 (0)