Skip to content

Commit e38e52b

Browse files
Merge pull request #4 from filipecalegario/master
Adding examples for ESP32 and M5StickC
2 parents f9b0969 + 486c27a commit e38e52b

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <WiFi.h>
2+
#include "mapper.h"
3+
4+
const char* ssid = "WIFI_SSID";
5+
const char* password = "WIFI_PASSWORD";
6+
7+
mapper_device dev = 0;
8+
mapper_signal input_signal = 0;
9+
mapper_signal output_signal = 0;
10+
float seq_number = 0;
11+
float received_value = 0;
12+
13+
void setup() {
14+
WiFi.begin(ssid, password);
15+
16+
while (WiFi.status() != WL_CONNECTED) {
17+
delay(500);
18+
}
19+
20+
float min = 0.0f;
21+
float max = 5.0f;
22+
23+
dev = mapper_device_new("ESP32", 0, 0);
24+
output_signal = mapper_device_add_output_signal(dev, "value_to_send", 1, 'f', "V", &min, &max);
25+
input_signal = mapper_device_add_input_signal(dev, "value_received", 1, 'f', 0, &min, &max, input_signal_handler, 0);
26+
}
27+
28+
void loop() {
29+
mapper_device_poll(dev, 120);
30+
seq_number = seq_number + 0.01f;
31+
mapper_signal_update_float(output_signal, seq_number);
32+
}
33+
34+
void input_signal_handler(mapper_signal sig, mapper_id instance, const void *value, int count, mapper_timetag_t *timetag) {
35+
if (value) {
36+
float *v = (float*)value;
37+
for (int i = 0; i < mapper_signal_length(sig); i++) {
38+
received_value = v[i];
39+
}
40+
}
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#include <WiFi.h>
2+
#include <M5StickC.h>
3+
#include "mapper.h"
4+
5+
const char* ssid = "WIFI_SSID";
6+
const char* password = "WIFI_PASSWORD";
7+
8+
mapper_device dev = 0;
9+
mapper_signal input_signal = 0;
10+
mapper_signal output_signal = 0;
11+
float seq_number = 0;
12+
float received_value = 0;
13+
14+
void setup() {
15+
// Initialize the M5StickC object
16+
M5.begin();
17+
18+
WiFi.begin(ssid, password);
19+
20+
while (WiFi.status() != WL_CONNECTED) {
21+
M5.Lcd.fillScreen(ORANGE);
22+
delay(250);
23+
M5.Lcd.fillScreen(RED);
24+
delay(250);
25+
M5.Lcd.println("Connecting");
26+
}
27+
28+
M5.Lcd.fillScreen(GREEN);
29+
30+
float min = 0.0f;
31+
float max = 5.0f;
32+
33+
dev = mapper_device_new("M5StickC", 0, 0);
34+
output_signal = mapper_device_add_output_signal(dev, "value_to_send", 1, 'f', "V", &min, &max);
35+
input_signal = mapper_device_add_input_signal(dev, "value_received", 1, 'f', 0, &min, &max, input_signal_handler, 0);
36+
37+
// LCD display
38+
// M5.Lcd.print("Hello World");
39+
40+
pinMode(M5_LED, OUTPUT);
41+
digitalWrite(M5_LED, HIGH);
42+
}
43+
44+
void loop() {
45+
mapper_device_poll(dev, 120);
46+
M5.Lcd.fillScreen(BLUE);
47+
seq_number = seq_number + 0.01f;
48+
mapper_signal_update_float(output_signal, seq_number);
49+
M5.Lcd.setCursor(0, 10);
50+
M5.Lcd.print(received_value);
51+
//delay(10);
52+
}
53+
54+
void input_signal_handler(mapper_signal sig, mapper_id instance, const void *value, int count, mapper_timetag_t *timetag) {
55+
if (value) {
56+
float *v = (float*)value;
57+
for (int i = 0; i < mapper_signal_length(sig); i++) {
58+
received_value = v[i];
59+
}
60+
}
61+
}

0 commit comments

Comments
 (0)