diff --git a/faa_button/faa_button.ino b/faa_button/faa_button.ino
index 141afc9..1881ee1 100644
--- a/faa_button/faa_button.ino
+++ b/faa_button/faa_button.ino
@@ -44,37 +44,37 @@ Scheduler runner;
int button_pin = D5;
bool button_pullup = false;
void button_read() {
- //
- if (button_pullup) pinMode(button_pin, INPUT_PULLUP);
- else pinMode(button_pin, INPUT);
- //
- static int last = 0;
- int val = digitalRead(button_pin);
- if (val != last) {
//
- byte mac[6];
- WiFi.macAddress(mac);
- uint32_t mac32 = (((((mac[2] << 8) + mac[3]) << 8) + mac[4]) << 8) + mac[5];
+ if (button_pullup) pinMode(button_pin, INPUT_PULLUP);
+ else pinMode(button_pin, INPUT);
//
- Hello hello(String(MY_SIGN), MY_ID, mac32); // the most basic 'hello'
- // and you can append some floats
- static int count = 0;
- count++;
- hello.h1 = (count % 1000);
- hello.h2 = val;
- // hello.h3 = 0;
- // hello.h4 = 0;
- //
- uint8_t frm_size = sizeof(Hello) + 2;
- uint8_t frm[frm_size];
- frm[0] = '{';
- memcpy(frm + 1, (uint8_t *) &hello, sizeof(Hello));
- frm[frm_size - 1] = '}';
- //
- esp_now_send(NULL, frm, frm_size); // to all peers in the list.
- //
- last = val;
- }
+ static int last = 0;
+ int val = digitalRead(button_pin);
+ if (val != last) {
+ //
+ byte mac[6];
+ WiFi.macAddress(mac);
+ uint32_t mac32 = (((((mac[2] << 8) + mac[3]) << 8) + mac[4]) << 8) + mac[5];
+ //
+ Hello hello(String(MY_SIGN), MY_ID, mac32); // the most basic 'hello'
+ // and you can append some floats
+ static int count = 0;
+ count++;
+ hello.h1 = (count % 1000);
+ hello.h2 = val;
+ // hello.h3 = 0;
+ // hello.h4 = 0;
+ //
+ uint8_t frm_size = sizeof(Hello) + 2;
+ uint8_t frm[frm_size];
+ frm[0] = '{';
+ memcpy(frm + 1, (uint8_t *) &hello, sizeof(Hello));
+ frm[frm_size - 1] = '}';
+ //
+ esp_now_send(NULL, frm, frm_size); // to all peers in the list.
+ //
+ last = val;
+ }
}
Task button_read_task(1, TASK_FOREVER, &button_read, &runner, true); // every 1 ms
@@ -87,124 +87,124 @@ Task button_read_task(1, TASK_FOREVER, &button_read, &runner, true); // every 1
#define LED_PIN 2
extern Task blink_task;
void blink() {
- //
- static int count = 0;
- count++;
- //
- switch (count % 4) {
- case 0:
- digitalWrite(LED_PIN, LOW); // first ON
- blink_task.delay(LED_ONTIME);
- break;
- case 1:
- digitalWrite(LED_PIN, HIGH); // first OFF
- blink_task.delay(LED_GAPTIME);
- break;
- case 2:
- digitalWrite(LED_PIN, LOW); // second ON
- blink_task.delay(LED_ONTIME);
- break;
- case 3:
- digitalWrite(LED_PIN, HIGH); // second OFF
- blink_task.delay(LED_PERIOD - 2* LED_ONTIME - LED_GAPTIME);
- break;
- }
+ //
+ static int count = 0;
+ count++;
+ //
+ switch (count % 4) {
+ case 0:
+ digitalWrite(LED_PIN, LOW); // first ON
+ blink_task.delay(LED_ONTIME);
+ break;
+ case 1:
+ digitalWrite(LED_PIN, HIGH); // first OFF
+ blink_task.delay(LED_GAPTIME);
+ break;
+ case 2:
+ digitalWrite(LED_PIN, LOW); // second ON
+ blink_task.delay(LED_ONTIME);
+ break;
+ case 3:
+ digitalWrite(LED_PIN, HIGH); // second OFF
+ blink_task.delay(LED_PERIOD - 2* LED_ONTIME - LED_GAPTIME);
+ break;
+ }
}
Task blink_task(0, TASK_FOREVER, &blink, &runner, true); // -> ENABLED, at start-up.
// on 'Note'
void onNoteHandler(Note & n) {
- //is it for me?
- if (n.id == MY_GROUP_ID || n.id == MY_ID) {
- //
- if (n.velocity < 0) n.velocity = 0;
- //
- if (n.pitch < 0) n.pitch = 0;
- button_pin = n.pitch;
- //button_pullup
- if (n.onoff == 1) {
- button_pullup = true;
- } else {
- button_pullup = false;
+ //is it for me?
+ if (n.id == MY_GROUP_ID || n.id == MY_ID) {
+ //
+ if (n.velocity < 0) n.velocity = 0;
+ //
+ if (n.pitch < 0) n.pitch = 0;
+ button_pin = n.pitch;
+ //button_pullup
+ if (n.onoff == 1) {
+ button_pullup = true;
+ } else {
+ button_pullup = false;
+ }
}
- }
}
// on 'receive'
void onDataReceive(uint8_t * mac, uint8_t *incomingData, uint8_t len) {
- //
- Serial.write(incomingData, len);
-
- // open => identify => use.
- if (incomingData[0] == '{' && incomingData[len - 1] == '}' && len == (sizeof(Hello) + 2)) {
- Hello hello("");
- memcpy((uint8_t *) &hello, incomingData + 1, sizeof(Hello));
//
- Serial.println(hello.to_string());
- }
+ Serial.write(incomingData, len);
- // open => identify => use.
- if (incomingData[0] == '[' && incomingData[len - 1] == ']' && len == (sizeof(Note) + 2)) {
- Note note;
- memcpy((uint8_t *) ¬e, incomingData + 1, sizeof(Note));
- onNoteHandler(note);
- //
- Serial.println(note.to_string());
- }
+ // open => identify => use.
+ if (incomingData[0] == '{' && incomingData[len - 1] == '}' && len == (sizeof(Hello) + 2)) {
+ Hello hello("");
+ memcpy((uint8_t *) &hello, incomingData + 1, sizeof(Hello));
+ //
+ Serial.println(hello.to_string());
+ }
+
+ // open => identify => use.
+ if (incomingData[0] == '[' && incomingData[len - 1] == ']' && len == (sizeof(Note) + 2)) {
+ Note note;
+ memcpy((uint8_t *) ¬e, incomingData + 1, sizeof(Note));
+ onNoteHandler(note);
+ //
+ Serial.println(note.to_string());
+ }
}
// on 'sent'
void onDataSent(uint8_t *mac, uint8_t sendStatus) {
- char buff[256] = "";
- sprintf(buff, "Delivery failed! -> %02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
- if (sendStatus != 0) Serial.println(buff);
+ char buff[256] = "";
+ sprintf(buff, "Delivery failed! -> %02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
+ if (sendStatus != 0) Serial.println(buff);
}
//
void setup() {
- //led
- pinMode(LED_PIN, OUTPUT);
+ //led
+ pinMode(LED_PIN, OUTPUT);
- //serial
- Serial.begin(115200);
- delay(100);
+ //serial
+ Serial.begin(115200);
+ delay(100);
- //info
- Serial.println();
- Serial.println();
- Serial.println("\"hi, i m your postman.\"");
- Serial.println("-");
- Serial.println("- my id: " + String(MY_ID) + ", gid: " + String(MY_GROUP_ID) + ", call me ==> \"" + String(MY_SIGN) + "\"");
- Serial.println("- mac address: " + WiFi.macAddress() + ", channel: " + String(WIFI_CHANNEL));
- Serial.println("-");
+ //info
+ Serial.println();
+ Serial.println();
+ Serial.println("\"hi, i m your postman.\"");
+ Serial.println("-");
+ Serial.println("- my id: " + String(MY_ID) + ", gid: " + String(MY_GROUP_ID) + ", call me ==> \"" + String(MY_SIGN) + "\"");
+ Serial.println("- mac address: " + WiFi.macAddress() + ", channel: " + String(WIFI_CHANNEL));
+ Serial.println("-");
- //wifi - disabled
- system_phy_set_max_tpw(0);
- WiFiMode_t node_type = WIFI_STA;
- WiFi.mode(node_type);
+ //wifi - disabled
+ system_phy_set_max_tpw(0);
+ WiFiMode_t node_type = WIFI_STA;
+ WiFi.mode(node_type);
- //esp-now
- if (esp_now_init() != 0) {
- Serial.println("Error initializing ESP-NOW");
- return;
- }
- esp_now_set_self_role(ESP_NOW_ROLE_COMBO);
- esp_now_register_send_cb(onDataSent);
- esp_now_register_recv_cb(onDataReceive);
- //
- Serial.println("- ! (esp_now_add_peer) ==> add a 'broadcast peer' (FF:FF:FF:FF:FF:FF).");
- uint8_t broadcastmac[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
- esp_now_add_peer(broadcastmac, ESP_NOW_ROLE_COMBO, 1, NULL, 0);
+ //esp-now
+ if (esp_now_init() != 0) {
+ Serial.println("Error initializing ESP-NOW");
+ return;
+ }
+ esp_now_set_self_role(ESP_NOW_ROLE_COMBO);
+ esp_now_register_send_cb(onDataSent);
+ esp_now_register_recv_cb(onDataReceive);
+ //
+ Serial.println("- ! (esp_now_add_peer) ==> add a 'broadcast peer' (FF:FF:FF:FF:FF:FF).");
+ uint8_t broadcastmac[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
+ esp_now_add_peer(broadcastmac, ESP_NOW_ROLE_COMBO, 1, NULL, 0);
- Serial.println("-");
- Serial.println("\".-.-.-. :)\"");
- Serial.println();
+ Serial.println("-");
+ Serial.println("\".-.-.-. :)\"");
+ Serial.println();
}
void loop() {
- //
- runner.execute();
- //
+ //
+ runner.execute();
+ //
}
diff --git a/faa_button/sketch.yaml b/faa_button/sketch.yaml
new file mode 100644
index 0000000..ee52428
--- /dev/null
+++ b/faa_button/sketch.yaml
@@ -0,0 +1,2 @@
+default_fqbn: esp8266:esp8266:nodemcuv2:baud=460800
+default_port: /dev/tty.SLAB_USBtoUART
diff --git a/faa_piano/faa_piano.ino b/faa_piano/faa_piano.ino
index 4a42fc8..3de081b 100644
--- a/faa_piano/faa_piano.ino
+++ b/faa_piano/faa_piano.ino
@@ -42,19 +42,49 @@ Scheduler runner;
//-*-*-*-*-*-*-*-*-*-*-*-*-
void port_read() {
- //
- byte port = 0;
- static byte port_prev = 0;
- port = 0x00;
- port |= (digitalRead(D1) ? 0x01 : 0x00);
- port |= (digitalRead(D2) ? 0x02 : 0x00);
- port |= (digitalRead(D3) ? 0x04 : 0x00); // by design, PULLED-UP, being used for the FLASH button.
- port |= (0 ? 0x08 : 0x00); // LED pin, skip
- port |= (digitalRead(D5) ? 0x10 : 0x00);
- port |= (digitalRead(D6) ? 0x20 : 0x00);
- port |= (digitalRead(D7) ? 0x40 : 0x00);
- port |= (digitalRead(D8) ? 0x80 : 0x00);
- if (port_prev != port) {
+ //
+ byte port = 0;
+ static byte port_prev = 0;
+ port = 0x00;
+ port |= (digitalRead(D1) ? 0x01 : 0x00);
+ port |= (digitalRead(D2) ? 0x02 : 0x00);
+ port |= (digitalRead(D3) ? 0x04 : 0x00); // by design, PULLED-UP, being used for the FLASH button.
+ port |= (0 ? 0x08 : 0x00); // LED pin, skip
+ port |= (digitalRead(D5) ? 0x10 : 0x00);
+ port |= (digitalRead(D6) ? 0x20 : 0x00);
+ port |= (digitalRead(D7) ? 0x40 : 0x00);
+ port |= (digitalRead(D8) ? 0x80 : 0x00);
+ if (port_prev != port) {
+ //
+ byte mac[6];
+ WiFi.macAddress(mac);
+ uint32_t mac32 = (((((mac[2] << 8) + mac[3]) << 8) + mac[4]) << 8) + mac[5];
+ //
+ Hello hello(String(MY_SIGN), MY_ID, mac32); // the most basic 'hello'
+ // and you can append some floats
+ static int count = 0;
+ count++;
+ hello.h1 = (count % 1000);
+ hello.h2 = 1; // 1:digital
+ hello.h3 = port;
+ // hello.h4 = 0;
+ //
+ uint8_t frm_size = sizeof(Hello) + 2;
+ uint8_t frm[frm_size];
+ frm[0] = '{';
+ memcpy(frm + 1, (uint8_t *) &hello, sizeof(Hello));
+ frm[frm_size - 1] = '}';
+ //
+ esp_now_send(NULL, frm, frm_size); // to all peers in the list.
+ //
+ port_prev = port;
+ }
+}
+Task port_read_task(1, TASK_FOREVER, &port_read, &runner, true); // every 1 ms
+//
+void volume_read() {
+ //
+ int val = analogRead(A0);
//
byte mac[6];
WiFi.macAddress(mac);
@@ -65,8 +95,8 @@ void port_read() {
static int count = 0;
count++;
hello.h1 = (count % 1000);
- hello.h2 = 1; // 1:digital
- hello.h3 = port;
+ hello.h2 = 2; //2: analog
+ hello.h3 = val;
// hello.h4 = 0;
//
uint8_t frm_size = sizeof(Hello) + 2;
@@ -77,36 +107,6 @@ void port_read() {
//
esp_now_send(NULL, frm, frm_size); // to all peers in the list.
//
- port_prev = port;
- }
-}
-Task port_read_task(1, TASK_FOREVER, &port_read, &runner, true); // every 1 ms
-//
-void volume_read() {
- //
- int val = analogRead(A0);
- //
- byte mac[6];
- WiFi.macAddress(mac);
- uint32_t mac32 = (((((mac[2] << 8) + mac[3]) << 8) + mac[4]) << 8) + mac[5];
- //
- Hello hello(String(MY_SIGN), MY_ID, mac32); // the most basic 'hello'
- // and you can append some floats
- static int count = 0;
- count++;
- hello.h1 = (count % 1000);
- hello.h2 = 2; //2: analog
- hello.h3 = val;
- // hello.h4 = 0;
- //
- uint8_t frm_size = sizeof(Hello) + 2;
- uint8_t frm[frm_size];
- frm[0] = '{';
- memcpy(frm + 1, (uint8_t *) &hello, sizeof(Hello));
- frm[frm_size - 1] = '}';
- //
- esp_now_send(NULL, frm, frm_size); // to all peers in the list.
- //
}
Task volume_read_task(50, TASK_FOREVER, &volume_read, &runner, false); // every 50 ms
//*-*-*-*-*-*-*-*-*-*-*-*-*
@@ -118,146 +118,146 @@ Task volume_read_task(50, TASK_FOREVER, &volume_read, &runner, false); // every
#define LED_PIN 2
extern Task blink_task;
void blink() {
- //
- static int count = 0;
- count++;
- //
- switch (count % 4) {
- case 0:
- digitalWrite(LED_PIN, LOW); // first ON
- blink_task.delay(LED_ONTIME);
- break;
- case 1:
- digitalWrite(LED_PIN, HIGH); // first OFF
- blink_task.delay(LED_GAPTIME);
- break;
- case 2:
- digitalWrite(LED_PIN, LOW); // second ON
- blink_task.delay(LED_ONTIME);
- break;
- case 3:
- digitalWrite(LED_PIN, HIGH); // second OFF
- blink_task.delay(LED_PERIOD - 2* LED_ONTIME - LED_GAPTIME);
- break;
- }
+ //
+ static int count = 0;
+ count++;
+ //
+ switch (count % 4) {
+ case 0:
+ digitalWrite(LED_PIN, LOW); // first ON
+ blink_task.delay(LED_ONTIME);
+ break;
+ case 1:
+ digitalWrite(LED_PIN, HIGH); // first OFF
+ blink_task.delay(LED_GAPTIME);
+ break;
+ case 2:
+ digitalWrite(LED_PIN, LOW); // second ON
+ blink_task.delay(LED_ONTIME);
+ break;
+ case 3:
+ digitalWrite(LED_PIN, HIGH); // second OFF
+ blink_task.delay(LED_PERIOD - 2* LED_ONTIME - LED_GAPTIME);
+ break;
+ }
}
Task blink_task(0, TASK_FOREVER, &blink, &runner, true); // -> ENABLED, at start-up.
// on 'Note'
void onNoteHandler(Note & n) {
- //is it for me?
- if (n.id == MY_GROUP_ID || n.id == MY_ID) {
- //
- if (n.velocity < 0) n.velocity = 0;
- if (n.pitch < 0) n.pitch = 0;
- //
- // volume: task control
- if (n.velocity == 0) {
- //schedule 1 read
- volume_read_task.disable();
- volume_read_task.setIterations(1);
- volume_read_task.restart();
- } else {
- // limiting max. speed.
- if (n.velocity < 20) n.velocity = 20;
- volume_read_task.setIterations(TASK_FOREVER);
- volume_read_task.setInterval(n.velocity);
- volume_read_task.restart();
+ //is it for me?
+ if (n.id == MY_GROUP_ID || n.id == MY_ID) {
+ //
+ if (n.velocity < 0) n.velocity = 0;
+ if (n.pitch < 0) n.pitch = 0;
+ //
+ // volume: task control
+ if (n.velocity == 0) {
+ //schedule 1 read
+ volume_read_task.disable();
+ volume_read_task.setIterations(1);
+ volume_read_task.restart();
+ } else {
+ // limiting max. speed.
+ if (n.velocity < 20) n.velocity = 20;
+ volume_read_task.setIterations(TASK_FOREVER);
+ volume_read_task.setInterval(n.velocity);
+ volume_read_task.restart();
+ }
+ //button: pullup on/off
+ if (n.onoff == 1) {
+ pinMode(n.pitch, INPUT_PULLUP);
+ } else {
+ pinMode(n.pitch, INPUT);
+ }
}
- //button: pullup on/off
- if (n.onoff == 1) {
- pinMode(n.pitch, INPUT_PULLUP);
- } else {
- pinMode(n.pitch, INPUT);
- }
- }
}
// on 'receive'
void onDataReceive(uint8_t * mac, uint8_t *incomingData, uint8_t len) {
- //
- Serial.write(incomingData, len);
-
- // open => identify => use.
- if (incomingData[0] == '{' && incomingData[len - 1] == '}' && len == (sizeof(Hello) + 2)) {
- Hello hello("");
- memcpy((uint8_t *) &hello, incomingData + 1, sizeof(Hello));
//
- Serial.println(hello.to_string());
- }
+ Serial.write(incomingData, len);
- // open => identify => use.
- if (incomingData[0] == '[' && incomingData[len - 1] == ']' && len == (sizeof(Note) + 2)) {
- Note note;
- memcpy((uint8_t *) ¬e, incomingData + 1, sizeof(Note));
- onNoteHandler(note);
- //
- Serial.println(note.to_string());
- }
+ // open => identify => use.
+ if (incomingData[0] == '{' && incomingData[len - 1] == '}' && len == (sizeof(Hello) + 2)) {
+ Hello hello("");
+ memcpy((uint8_t *) &hello, incomingData + 1, sizeof(Hello));
+ //
+ Serial.println(hello.to_string());
+ }
+
+ // open => identify => use.
+ if (incomingData[0] == '[' && incomingData[len - 1] == ']' && len == (sizeof(Note) + 2)) {
+ Note note;
+ memcpy((uint8_t *) ¬e, incomingData + 1, sizeof(Note));
+ onNoteHandler(note);
+ //
+ Serial.println(note.to_string());
+ }
}
// on 'sent'
void onDataSent(uint8_t *mac, uint8_t sendStatus) {
- char buff[256] = "";
- sprintf(buff, "Delivery failed! -> %02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
- if (sendStatus != 0) Serial.println(buff);
+ char buff[256] = "";
+ sprintf(buff, "Delivery failed! -> %02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
+ if (sendStatus != 0) Serial.println(buff);
}
//
void setup() {
- //led
- pinMode(LED_PIN, OUTPUT);
+ //led
+ pinMode(LED_PIN, OUTPUT);
- //input
- pinMode(D1, INPUT);
- pinMode(D2, INPUT);
- pinMode(D3, INPUT);
- //
- pinMode(D5, INPUT);
- pinMode(D6, INPUT);
- pinMode(D7, INPUT);
- pinMode(D8, INPUT);
+ //input
+ pinMode(D1, INPUT);
+ pinMode(D2, INPUT);
+ pinMode(D3, INPUT);
+ //
+ pinMode(D5, INPUT);
+ pinMode(D6, INPUT);
+ pinMode(D7, INPUT);
+ pinMode(D8, INPUT);
- //serial
- Serial.begin(115200);
- delay(100);
+ //serial
+ Serial.begin(115200);
+ delay(100);
- //info
- Serial.println();
- Serial.println();
- Serial.println("\"hi, i m your postman.\"");
- Serial.println("-");
- Serial.println("- my id: " + String(MY_ID) + ", gid: " + String(MY_GROUP_ID) + ", call me ==> \"" + String(MY_SIGN) + "\"");
- Serial.println("- mac address: " + WiFi.macAddress() + ", channel: " + String(WIFI_CHANNEL));
- Serial.println("-");
+ //info
+ Serial.println();
+ Serial.println();
+ Serial.println("\"hi, i m your postman.\"");
+ Serial.println("-");
+ Serial.println("- my id: " + String(MY_ID) + ", gid: " + String(MY_GROUP_ID) + ", call me ==> \"" + String(MY_SIGN) + "\"");
+ Serial.println("- mac address: " + WiFi.macAddress() + ", channel: " + String(WIFI_CHANNEL));
+ Serial.println("-");
- //wifi - disabled
- system_phy_set_max_tpw(0);
- WiFiMode_t node_type = WIFI_STA;
- WiFi.mode(node_type);
+ //wifi - disabled
+ system_phy_set_max_tpw(0);
+ WiFiMode_t node_type = WIFI_STA;
+ WiFi.mode(node_type);
- //esp-now
- if (esp_now_init() != 0) {
- Serial.println("Error initializing ESP-NOW");
- return;
- }
- esp_now_set_self_role(ESP_NOW_ROLE_COMBO);
- esp_now_register_send_cb(onDataSent);
- esp_now_register_recv_cb(onDataReceive);
- //
- Serial.println("- ! (esp_now_add_peer) ==> add a 'broadcast peer' (FF:FF:FF:FF:FF:FF).");
- uint8_t broadcastmac[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
- esp_now_add_peer(broadcastmac, ESP_NOW_ROLE_COMBO, 1, NULL, 0);
+ //esp-now
+ if (esp_now_init() != 0) {
+ Serial.println("Error initializing ESP-NOW");
+ return;
+ }
+ esp_now_set_self_role(ESP_NOW_ROLE_COMBO);
+ esp_now_register_send_cb(onDataSent);
+ esp_now_register_recv_cb(onDataReceive);
+ //
+ Serial.println("- ! (esp_now_add_peer) ==> add a 'broadcast peer' (FF:FF:FF:FF:FF:FF).");
+ uint8_t broadcastmac[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
+ esp_now_add_peer(broadcastmac, ESP_NOW_ROLE_COMBO, 1, NULL, 0);
- Serial.println("-");
- Serial.println("\".-.-.-. :)\"");
- Serial.println();
+ Serial.println("-");
+ Serial.println("\".-.-.-. :)\"");
+ Serial.println();
}
void loop() {
- //
- runner.execute();
- //
+ //
+ runner.execute();
+ //
}
diff --git a/faa_piano/sketch.yaml b/faa_piano/sketch.yaml
new file mode 100644
index 0000000..ee52428
--- /dev/null
+++ b/faa_piano/sketch.yaml
@@ -0,0 +1,2 @@
+default_fqbn: esp8266:esp8266:nodemcuv2:baud=460800
+default_port: /dev/tty.SLAB_USBtoUART
diff --git a/faa_roller/sketch.yaml b/faa_roller/sketch.yaml
new file mode 100644
index 0000000..ee52428
--- /dev/null
+++ b/faa_roller/sketch.yaml
@@ -0,0 +1,2 @@
+default_fqbn: esp8266:esp8266:nodemcuv2:baud=460800
+default_port: /dev/tty.SLAB_USBtoUART
diff --git a/faa_taak/faa_taak.ino b/faa_taak/faa_taak.ino
index 48b8144..70d547c 100644
--- a/faa_taak/faa_taak.ino
+++ b/faa_taak/faa_taak.ino
@@ -18,7 +18,7 @@
//========================
#define MY_GROUP_ID (1000)
-#define MY_ID (MY_GROUP_ID + 1)
+#define MY_ID (MY_GROUP_ID + 777)
#define MY_SIGN ("TAAK")
//========================
@@ -43,16 +43,16 @@ Scheduler runner;
//-*-*-*-*-*-*-*-*-*-*-*-*-
int taak_pin = D6;
void taak_on() {
- pinMode(taak_pin, OUTPUT);
- Serial.println("taak_on!");
- digitalWrite(taak_pin, HIGH);
+ pinMode(taak_pin, OUTPUT);
+ Serial.println("taak_on!");
+ digitalWrite(taak_pin, HIGH);
}
Task taak_on_task(0, TASK_ONCE, &taak_on, &runner, false);
void taak_off() {
- pinMode(taak_pin, OUTPUT);
- Serial.println("taak_off!");
- digitalWrite(taak_pin, LOW);
+ pinMode(taak_pin, OUTPUT);
+ Serial.println("taak_off!");
+ digitalWrite(taak_pin, LOW);
}
Task taak_off_task(0, TASK_ONCE, &taak_off, &runner, false);
//*-*-*-*-*-*-*-*-*-*-*-*-*
@@ -64,131 +64,131 @@ Task taak_off_task(0, TASK_ONCE, &taak_off, &runner, false);
#define LED_PIN 2
extern Task blink_task;
void blink() {
- //
- static int count = 0;
- count++;
- //
- switch (count % 4) {
- case 0:
- digitalWrite(LED_PIN, LOW); // first ON
- blink_task.delay(LED_ONTIME);
- break;
- case 1:
- digitalWrite(LED_PIN, HIGH); // first OFF
- blink_task.delay(LED_GAPTIME);
- break;
- case 2:
- digitalWrite(LED_PIN, LOW); // second ON
- blink_task.delay(LED_ONTIME);
- break;
- case 3:
- digitalWrite(LED_PIN, HIGH); // second OFF
- blink_task.delay(LED_PERIOD - 2* LED_ONTIME - LED_GAPTIME);
- break;
- }
+ //
+ static int count = 0;
+ count++;
+ //
+ switch (count % 4) {
+ case 0:
+ digitalWrite(LED_PIN, LOW); // first ON
+ blink_task.delay(LED_ONTIME);
+ break;
+ case 1:
+ digitalWrite(LED_PIN, HIGH); // first OFF
+ blink_task.delay(LED_GAPTIME);
+ break;
+ case 2:
+ digitalWrite(LED_PIN, LOW); // second ON
+ blink_task.delay(LED_ONTIME);
+ break;
+ case 3:
+ digitalWrite(LED_PIN, HIGH); // second OFF
+ blink_task.delay(LED_PERIOD - 2* LED_ONTIME - LED_GAPTIME);
+ break;
+ }
}
Task blink_task(0, TASK_FOREVER, &blink, &runner, true); // -> ENABLED, at start-up.
// on 'Note'
void onNoteHandler(Note & n) {
- //is it for me?
- if (n.id == MY_GROUP_ID || n.id == MY_ID) {
- //
- if (n.velocity < 0) n.velocity = 0;
- //
- if (n.pitch < 0) n.pitch = 0;
- taak_pin = n.pitch;
- //taak_on && taak_off
- if (n.velocity == 0) {
- if (n.onoff == 1) {
- taak_on_task.restartDelayed(10);
- } else {
- taak_off_task.restartDelayed(10);
- }
+ //is it for me?
+ if (n.id == MY_GROUP_ID || n.id == MY_ID) {
+ //
+ if (n.velocity < 0) n.velocity = 0;
+ //
+ if (n.pitch < 0) n.pitch = 0;
+ taak_pin = n.pitch;
+ //taak_on && taak_off
+ if (n.velocity == 0) {
+ if (n.onoff == 1) {
+ taak_on_task.restartDelayed(10);
+ } else {
+ taak_off_task.restartDelayed(10);
+ }
+ }
+ //taak_hit
+ else {
+ taak_on_task.restartDelayed(10);
+ taak_off_task.restartDelayed(10 + n.velocity * 2);
+ }
}
- //taak_hit
- else {
- taak_on_task.restartDelayed(10);
- taak_off_task.restartDelayed(10 + n.velocity * 2);
- }
- }
}
// on 'receive'
void onDataReceive(uint8_t * mac, uint8_t *incomingData, uint8_t len) {
- //
- Serial.write(incomingData, len);
-
- // open => identify => use.
- if (incomingData[0] == '{' && incomingData[len - 1] == '}' && len == (sizeof(Hello) + 2)) {
- Hello hello("");
- memcpy((uint8_t *) &hello, incomingData + 1, sizeof(Hello));
//
- Serial.println(hello.to_string());
- }
+ Serial.write(incomingData, len);
- // open => identify => use.
- if (incomingData[0] == '[' && incomingData[len - 1] == ']' && len == (sizeof(Note) + 2)) {
- Note note;
- memcpy((uint8_t *) ¬e, incomingData + 1, sizeof(Note));
- onNoteHandler(note);
- //
- Serial.println(note.to_string());
- }
+ // open => identify => use.
+ if (incomingData[0] == '{' && incomingData[len - 1] == '}' && len == (sizeof(Hello) + 2)) {
+ Hello hello("");
+ memcpy((uint8_t *) &hello, incomingData + 1, sizeof(Hello));
+ //
+ Serial.println(hello.to_string());
+ }
+
+ // open => identify => use.
+ if (incomingData[0] == '[' && incomingData[len - 1] == ']' && len == (sizeof(Note) + 2)) {
+ Note note;
+ memcpy((uint8_t *) ¬e, incomingData + 1, sizeof(Note));
+ onNoteHandler(note);
+ //
+ Serial.println(note.to_string());
+ }
}
// on 'sent'
void onDataSent(uint8_t *mac, uint8_t sendStatus) {
- char buff[256] = "";
- sprintf(buff, "Delivery failed! -> %02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
- if (sendStatus != 0) Serial.println(buff);
+ char buff[256] = "";
+ sprintf(buff, "Delivery failed! -> %02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
+ if (sendStatus != 0) Serial.println(buff);
}
//
void setup() {
- //led
- pinMode(LED_PIN, OUTPUT);
+ //led
+ pinMode(LED_PIN, OUTPUT);
- //serial
- Serial.begin(115200);
- delay(100);
+ //serial
+ Serial.begin(115200);
+ delay(100);
- //info
- Serial.println();
- Serial.println();
- Serial.println("\"hi, i m your postman.\"");
- Serial.println("-");
- Serial.println("- my id: " + String(MY_ID) + ", gid: " + String(MY_GROUP_ID) + ", call me ==> \"" + String(MY_SIGN) + "\"");
- Serial.println("- mac address: " + WiFi.macAddress() + ", channel: " + String(WIFI_CHANNEL));
- Serial.println("-");
+ //info
+ Serial.println();
+ Serial.println();
+ Serial.println("\"hi, i m your postman.\"");
+ Serial.println("-");
+ Serial.println("- my id: " + String(MY_ID) + ", gid: " + String(MY_GROUP_ID) + ", call me ==> \"" + String(MY_SIGN) + "\"");
+ Serial.println("- mac address: " + WiFi.macAddress() + ", channel: " + String(WIFI_CHANNEL));
+ Serial.println("-");
- //wifi - disabled
- system_phy_set_max_tpw(0);
- WiFiMode_t node_type = WIFI_STA;
- WiFi.mode(node_type);
+ //wifi - disabled
+ system_phy_set_max_tpw(0);
+ WiFiMode_t node_type = WIFI_STA;
+ WiFi.mode(node_type);
- //esp-now
- if (esp_now_init() != 0) {
- Serial.println("Error initializing ESP-NOW");
- return;
- }
- esp_now_set_self_role(ESP_NOW_ROLE_COMBO);
- esp_now_register_send_cb(onDataSent);
- esp_now_register_recv_cb(onDataReceive);
- //
- Serial.println("- ! (esp_now_add_peer) ==> add a 'broadcast peer' (FF:FF:FF:FF:FF:FF).");
- uint8_t broadcastmac[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
- esp_now_add_peer(broadcastmac, ESP_NOW_ROLE_COMBO, 1, NULL, 0);
+ //esp-now
+ if (esp_now_init() != 0) {
+ Serial.println("Error initializing ESP-NOW");
+ return;
+ }
+ esp_now_set_self_role(ESP_NOW_ROLE_COMBO);
+ esp_now_register_send_cb(onDataSent);
+ esp_now_register_recv_cb(onDataReceive);
+ //
+ Serial.println("- ! (esp_now_add_peer) ==> add a 'broadcast peer' (FF:FF:FF:FF:FF:FF).");
+ uint8_t broadcastmac[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
+ esp_now_add_peer(broadcastmac, ESP_NOW_ROLE_COMBO, 1, NULL, 0);
- Serial.println("-");
- Serial.println("\".-.-.-. :)\"");
- Serial.println();
+ Serial.println("-");
+ Serial.println("\".-.-.-. :)\"");
+ Serial.println();
}
void loop() {
- //
- runner.execute();
- //
+ //
+ runner.execute();
+ //
}
diff --git a/faa_taak/sketch.yaml b/faa_taak/sketch.yaml
new file mode 100644
index 0000000..ee52428
--- /dev/null
+++ b/faa_taak/sketch.yaml
@@ -0,0 +1,2 @@
+default_fqbn: esp8266:esp8266:nodemcuv2:baud=460800
+default_port: /dev/tty.SLAB_USBtoUART
diff --git a/faa_tone/faa_tone.ino b/faa_tone/faa_tone.ino
index 4a42fc8..3de081b 100644
--- a/faa_tone/faa_tone.ino
+++ b/faa_tone/faa_tone.ino
@@ -42,19 +42,49 @@ Scheduler runner;
//-*-*-*-*-*-*-*-*-*-*-*-*-
void port_read() {
- //
- byte port = 0;
- static byte port_prev = 0;
- port = 0x00;
- port |= (digitalRead(D1) ? 0x01 : 0x00);
- port |= (digitalRead(D2) ? 0x02 : 0x00);
- port |= (digitalRead(D3) ? 0x04 : 0x00); // by design, PULLED-UP, being used for the FLASH button.
- port |= (0 ? 0x08 : 0x00); // LED pin, skip
- port |= (digitalRead(D5) ? 0x10 : 0x00);
- port |= (digitalRead(D6) ? 0x20 : 0x00);
- port |= (digitalRead(D7) ? 0x40 : 0x00);
- port |= (digitalRead(D8) ? 0x80 : 0x00);
- if (port_prev != port) {
+ //
+ byte port = 0;
+ static byte port_prev = 0;
+ port = 0x00;
+ port |= (digitalRead(D1) ? 0x01 : 0x00);
+ port |= (digitalRead(D2) ? 0x02 : 0x00);
+ port |= (digitalRead(D3) ? 0x04 : 0x00); // by design, PULLED-UP, being used for the FLASH button.
+ port |= (0 ? 0x08 : 0x00); // LED pin, skip
+ port |= (digitalRead(D5) ? 0x10 : 0x00);
+ port |= (digitalRead(D6) ? 0x20 : 0x00);
+ port |= (digitalRead(D7) ? 0x40 : 0x00);
+ port |= (digitalRead(D8) ? 0x80 : 0x00);
+ if (port_prev != port) {
+ //
+ byte mac[6];
+ WiFi.macAddress(mac);
+ uint32_t mac32 = (((((mac[2] << 8) + mac[3]) << 8) + mac[4]) << 8) + mac[5];
+ //
+ Hello hello(String(MY_SIGN), MY_ID, mac32); // the most basic 'hello'
+ // and you can append some floats
+ static int count = 0;
+ count++;
+ hello.h1 = (count % 1000);
+ hello.h2 = 1; // 1:digital
+ hello.h3 = port;
+ // hello.h4 = 0;
+ //
+ uint8_t frm_size = sizeof(Hello) + 2;
+ uint8_t frm[frm_size];
+ frm[0] = '{';
+ memcpy(frm + 1, (uint8_t *) &hello, sizeof(Hello));
+ frm[frm_size - 1] = '}';
+ //
+ esp_now_send(NULL, frm, frm_size); // to all peers in the list.
+ //
+ port_prev = port;
+ }
+}
+Task port_read_task(1, TASK_FOREVER, &port_read, &runner, true); // every 1 ms
+//
+void volume_read() {
+ //
+ int val = analogRead(A0);
//
byte mac[6];
WiFi.macAddress(mac);
@@ -65,8 +95,8 @@ void port_read() {
static int count = 0;
count++;
hello.h1 = (count % 1000);
- hello.h2 = 1; // 1:digital
- hello.h3 = port;
+ hello.h2 = 2; //2: analog
+ hello.h3 = val;
// hello.h4 = 0;
//
uint8_t frm_size = sizeof(Hello) + 2;
@@ -77,36 +107,6 @@ void port_read() {
//
esp_now_send(NULL, frm, frm_size); // to all peers in the list.
//
- port_prev = port;
- }
-}
-Task port_read_task(1, TASK_FOREVER, &port_read, &runner, true); // every 1 ms
-//
-void volume_read() {
- //
- int val = analogRead(A0);
- //
- byte mac[6];
- WiFi.macAddress(mac);
- uint32_t mac32 = (((((mac[2] << 8) + mac[3]) << 8) + mac[4]) << 8) + mac[5];
- //
- Hello hello(String(MY_SIGN), MY_ID, mac32); // the most basic 'hello'
- // and you can append some floats
- static int count = 0;
- count++;
- hello.h1 = (count % 1000);
- hello.h2 = 2; //2: analog
- hello.h3 = val;
- // hello.h4 = 0;
- //
- uint8_t frm_size = sizeof(Hello) + 2;
- uint8_t frm[frm_size];
- frm[0] = '{';
- memcpy(frm + 1, (uint8_t *) &hello, sizeof(Hello));
- frm[frm_size - 1] = '}';
- //
- esp_now_send(NULL, frm, frm_size); // to all peers in the list.
- //
}
Task volume_read_task(50, TASK_FOREVER, &volume_read, &runner, false); // every 50 ms
//*-*-*-*-*-*-*-*-*-*-*-*-*
@@ -118,146 +118,146 @@ Task volume_read_task(50, TASK_FOREVER, &volume_read, &runner, false); // every
#define LED_PIN 2
extern Task blink_task;
void blink() {
- //
- static int count = 0;
- count++;
- //
- switch (count % 4) {
- case 0:
- digitalWrite(LED_PIN, LOW); // first ON
- blink_task.delay(LED_ONTIME);
- break;
- case 1:
- digitalWrite(LED_PIN, HIGH); // first OFF
- blink_task.delay(LED_GAPTIME);
- break;
- case 2:
- digitalWrite(LED_PIN, LOW); // second ON
- blink_task.delay(LED_ONTIME);
- break;
- case 3:
- digitalWrite(LED_PIN, HIGH); // second OFF
- blink_task.delay(LED_PERIOD - 2* LED_ONTIME - LED_GAPTIME);
- break;
- }
+ //
+ static int count = 0;
+ count++;
+ //
+ switch (count % 4) {
+ case 0:
+ digitalWrite(LED_PIN, LOW); // first ON
+ blink_task.delay(LED_ONTIME);
+ break;
+ case 1:
+ digitalWrite(LED_PIN, HIGH); // first OFF
+ blink_task.delay(LED_GAPTIME);
+ break;
+ case 2:
+ digitalWrite(LED_PIN, LOW); // second ON
+ blink_task.delay(LED_ONTIME);
+ break;
+ case 3:
+ digitalWrite(LED_PIN, HIGH); // second OFF
+ blink_task.delay(LED_PERIOD - 2* LED_ONTIME - LED_GAPTIME);
+ break;
+ }
}
Task blink_task(0, TASK_FOREVER, &blink, &runner, true); // -> ENABLED, at start-up.
// on 'Note'
void onNoteHandler(Note & n) {
- //is it for me?
- if (n.id == MY_GROUP_ID || n.id == MY_ID) {
- //
- if (n.velocity < 0) n.velocity = 0;
- if (n.pitch < 0) n.pitch = 0;
- //
- // volume: task control
- if (n.velocity == 0) {
- //schedule 1 read
- volume_read_task.disable();
- volume_read_task.setIterations(1);
- volume_read_task.restart();
- } else {
- // limiting max. speed.
- if (n.velocity < 20) n.velocity = 20;
- volume_read_task.setIterations(TASK_FOREVER);
- volume_read_task.setInterval(n.velocity);
- volume_read_task.restart();
+ //is it for me?
+ if (n.id == MY_GROUP_ID || n.id == MY_ID) {
+ //
+ if (n.velocity < 0) n.velocity = 0;
+ if (n.pitch < 0) n.pitch = 0;
+ //
+ // volume: task control
+ if (n.velocity == 0) {
+ //schedule 1 read
+ volume_read_task.disable();
+ volume_read_task.setIterations(1);
+ volume_read_task.restart();
+ } else {
+ // limiting max. speed.
+ if (n.velocity < 20) n.velocity = 20;
+ volume_read_task.setIterations(TASK_FOREVER);
+ volume_read_task.setInterval(n.velocity);
+ volume_read_task.restart();
+ }
+ //button: pullup on/off
+ if (n.onoff == 1) {
+ pinMode(n.pitch, INPUT_PULLUP);
+ } else {
+ pinMode(n.pitch, INPUT);
+ }
}
- //button: pullup on/off
- if (n.onoff == 1) {
- pinMode(n.pitch, INPUT_PULLUP);
- } else {
- pinMode(n.pitch, INPUT);
- }
- }
}
// on 'receive'
void onDataReceive(uint8_t * mac, uint8_t *incomingData, uint8_t len) {
- //
- Serial.write(incomingData, len);
-
- // open => identify => use.
- if (incomingData[0] == '{' && incomingData[len - 1] == '}' && len == (sizeof(Hello) + 2)) {
- Hello hello("");
- memcpy((uint8_t *) &hello, incomingData + 1, sizeof(Hello));
//
- Serial.println(hello.to_string());
- }
+ Serial.write(incomingData, len);
- // open => identify => use.
- if (incomingData[0] == '[' && incomingData[len - 1] == ']' && len == (sizeof(Note) + 2)) {
- Note note;
- memcpy((uint8_t *) ¬e, incomingData + 1, sizeof(Note));
- onNoteHandler(note);
- //
- Serial.println(note.to_string());
- }
+ // open => identify => use.
+ if (incomingData[0] == '{' && incomingData[len - 1] == '}' && len == (sizeof(Hello) + 2)) {
+ Hello hello("");
+ memcpy((uint8_t *) &hello, incomingData + 1, sizeof(Hello));
+ //
+ Serial.println(hello.to_string());
+ }
+
+ // open => identify => use.
+ if (incomingData[0] == '[' && incomingData[len - 1] == ']' && len == (sizeof(Note) + 2)) {
+ Note note;
+ memcpy((uint8_t *) ¬e, incomingData + 1, sizeof(Note));
+ onNoteHandler(note);
+ //
+ Serial.println(note.to_string());
+ }
}
// on 'sent'
void onDataSent(uint8_t *mac, uint8_t sendStatus) {
- char buff[256] = "";
- sprintf(buff, "Delivery failed! -> %02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
- if (sendStatus != 0) Serial.println(buff);
+ char buff[256] = "";
+ sprintf(buff, "Delivery failed! -> %02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
+ if (sendStatus != 0) Serial.println(buff);
}
//
void setup() {
- //led
- pinMode(LED_PIN, OUTPUT);
+ //led
+ pinMode(LED_PIN, OUTPUT);
- //input
- pinMode(D1, INPUT);
- pinMode(D2, INPUT);
- pinMode(D3, INPUT);
- //
- pinMode(D5, INPUT);
- pinMode(D6, INPUT);
- pinMode(D7, INPUT);
- pinMode(D8, INPUT);
+ //input
+ pinMode(D1, INPUT);
+ pinMode(D2, INPUT);
+ pinMode(D3, INPUT);
+ //
+ pinMode(D5, INPUT);
+ pinMode(D6, INPUT);
+ pinMode(D7, INPUT);
+ pinMode(D8, INPUT);
- //serial
- Serial.begin(115200);
- delay(100);
+ //serial
+ Serial.begin(115200);
+ delay(100);
- //info
- Serial.println();
- Serial.println();
- Serial.println("\"hi, i m your postman.\"");
- Serial.println("-");
- Serial.println("- my id: " + String(MY_ID) + ", gid: " + String(MY_GROUP_ID) + ", call me ==> \"" + String(MY_SIGN) + "\"");
- Serial.println("- mac address: " + WiFi.macAddress() + ", channel: " + String(WIFI_CHANNEL));
- Serial.println("-");
+ //info
+ Serial.println();
+ Serial.println();
+ Serial.println("\"hi, i m your postman.\"");
+ Serial.println("-");
+ Serial.println("- my id: " + String(MY_ID) + ", gid: " + String(MY_GROUP_ID) + ", call me ==> \"" + String(MY_SIGN) + "\"");
+ Serial.println("- mac address: " + WiFi.macAddress() + ", channel: " + String(WIFI_CHANNEL));
+ Serial.println("-");
- //wifi - disabled
- system_phy_set_max_tpw(0);
- WiFiMode_t node_type = WIFI_STA;
- WiFi.mode(node_type);
+ //wifi - disabled
+ system_phy_set_max_tpw(0);
+ WiFiMode_t node_type = WIFI_STA;
+ WiFi.mode(node_type);
- //esp-now
- if (esp_now_init() != 0) {
- Serial.println("Error initializing ESP-NOW");
- return;
- }
- esp_now_set_self_role(ESP_NOW_ROLE_COMBO);
- esp_now_register_send_cb(onDataSent);
- esp_now_register_recv_cb(onDataReceive);
- //
- Serial.println("- ! (esp_now_add_peer) ==> add a 'broadcast peer' (FF:FF:FF:FF:FF:FF).");
- uint8_t broadcastmac[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
- esp_now_add_peer(broadcastmac, ESP_NOW_ROLE_COMBO, 1, NULL, 0);
+ //esp-now
+ if (esp_now_init() != 0) {
+ Serial.println("Error initializing ESP-NOW");
+ return;
+ }
+ esp_now_set_self_role(ESP_NOW_ROLE_COMBO);
+ esp_now_register_send_cb(onDataSent);
+ esp_now_register_recv_cb(onDataReceive);
+ //
+ Serial.println("- ! (esp_now_add_peer) ==> add a 'broadcast peer' (FF:FF:FF:FF:FF:FF).");
+ uint8_t broadcastmac[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
+ esp_now_add_peer(broadcastmac, ESP_NOW_ROLE_COMBO, 1, NULL, 0);
- Serial.println("-");
- Serial.println("\".-.-.-. :)\"");
- Serial.println();
+ Serial.println("-");
+ Serial.println("\".-.-.-. :)\"");
+ Serial.println();
}
void loop() {
- //
- runner.execute();
- //
+ //
+ runner.execute();
+ //
}
diff --git a/faa_tone/sketch.yaml b/faa_tone/sketch.yaml
new file mode 100644
index 0000000..ee52428
--- /dev/null
+++ b/faa_tone/sketch.yaml
@@ -0,0 +1,2 @@
+default_fqbn: esp8266:esp8266:nodemcuv2:baud=460800
+default_port: /dev/tty.SLAB_USBtoUART
diff --git a/faa_volume/faa_volume.ino b/faa_volume/faa_volume.ino
index 21db0cb..30c9d5d 100644
--- a/faa_volume/faa_volume.ino
+++ b/faa_volume/faa_volume.ino
@@ -18,7 +18,7 @@
//========================
#define MY_GROUP_ID (6000)
-#define MY_ID (MY_GROUP_ID + 1)
+#define MY_ID (MY_GROUP_ID + 3)
#define MY_SIGN ("VOLUME")
//========================
@@ -44,35 +44,35 @@ Scheduler runner;
int volume_pin = A0;
bool volume_pullup = false;
void volume_read() {
- //
- if (volume_pullup) pinMode(volume_pin, INPUT_PULLUP);
- else pinMode(volume_pin, INPUT);
- //
- int val = analogRead(volume_pin);
- //
- Serial.println(val);
- //
- byte mac[6];
- WiFi.macAddress(mac);
- uint32_t mac32 = (((((mac[2] << 8) + mac[3]) << 8) + mac[4]) << 8) + mac[5];
- //
- Hello hello(String(MY_SIGN), MY_ID, mac32); // the most basic 'hello'
- // and you can append some floats
- static int count = 0;
- count++;
- hello.h1 = (count % 1000);
- hello.h2 = val;
- // hello.h3 = 0;
- // hello.h4 = 0;
- //
- uint8_t frm_size = sizeof(Hello) + 2;
- uint8_t frm[frm_size];
- frm[0] = '{';
- memcpy(frm + 1, (uint8_t *) &hello, sizeof(Hello));
- frm[frm_size - 1] = '}';
- //
- esp_now_send(NULL, frm, frm_size); // to all peers in the list.
- //
+ //
+ if (volume_pullup) pinMode(volume_pin, INPUT_PULLUP);
+ else pinMode(volume_pin, INPUT);
+ //
+ int val = analogRead(volume_pin);
+ //
+ Serial.println(val);
+ //
+ byte mac[6];
+ WiFi.macAddress(mac);
+ uint32_t mac32 = (((((mac[2] << 8) + mac[3]) << 8) + mac[4]) << 8) + mac[5];
+ //
+ Hello hello(String(MY_SIGN), MY_ID, mac32); // the most basic 'hello'
+ // and you can append some floats
+ static int count = 0;
+ count++;
+ hello.h1 = (count % 1000);
+ hello.h2 = val;
+ // hello.h3 = 0;
+ // hello.h4 = 0;
+ //
+ uint8_t frm_size = sizeof(Hello) + 2;
+ uint8_t frm[frm_size];
+ frm[0] = '{';
+ memcpy(frm + 1, (uint8_t *) &hello, sizeof(Hello));
+ frm[frm_size - 1] = '}';
+ //
+ esp_now_send(NULL, frm, frm_size); // to all peers in the list.
+ //
}
Task volume_read_task(50, TASK_FOREVER, &volume_read, &runner, true); // every 1 ms
@@ -85,137 +85,137 @@ Task volume_read_task(50, TASK_FOREVER, &volume_read, &runner, true); // every 1
#define LED_PIN 2
extern Task blink_task;
void blink() {
- //
- static int count = 0;
- count++;
- //
- switch (count % 4) {
- case 0:
- digitalWrite(LED_PIN, LOW); // first ON
- blink_task.delay(LED_ONTIME);
- break;
- case 1:
- digitalWrite(LED_PIN, HIGH); // first OFF
- blink_task.delay(LED_GAPTIME);
- break;
- case 2:
- digitalWrite(LED_PIN, LOW); // second ON
- blink_task.delay(LED_ONTIME);
- break;
- case 3:
- digitalWrite(LED_PIN, HIGH); // second OFF
- blink_task.delay(LED_PERIOD - 2* LED_ONTIME - LED_GAPTIME);
- break;
- }
+ //
+ static int count = 0;
+ count++;
+ //
+ switch (count % 4) {
+ case 0:
+ digitalWrite(LED_PIN, LOW); // first ON
+ blink_task.delay(LED_ONTIME);
+ break;
+ case 1:
+ digitalWrite(LED_PIN, HIGH); // first OFF
+ blink_task.delay(LED_GAPTIME);
+ break;
+ case 2:
+ digitalWrite(LED_PIN, LOW); // second ON
+ blink_task.delay(LED_ONTIME);
+ break;
+ case 3:
+ digitalWrite(LED_PIN, HIGH); // second OFF
+ blink_task.delay(LED_PERIOD - 2* LED_ONTIME - LED_GAPTIME);
+ break;
+ }
}
Task blink_task(0, TASK_FOREVER, &blink, &runner, true); // -> ENABLED, at start-up.
// on 'Note'
void onNoteHandler(Note & n) {
- //is it for me?
- if (n.id == MY_GROUP_ID || n.id == MY_ID) {
- //
- if (n.pitch < 0) n.pitch = 0;
- volume_pin = n.pitch; //useless: for esp8266, A0 is only one adc.
- //
- if (n.velocity < 0) n.velocity = 0;
- //
- if (n.velocity == 0) {
- //schedule 1 read
- volume_read_task.disable();
- volume_read_task.setIterations(1);
- volume_read_task.restart();
- } else {
- // limiting max. speed.
- if (n.velocity < 20) n.velocity = 20;
- volume_read_task.setIterations(TASK_FOREVER);
- volume_read_task.setInterval(n.velocity);
- volume_read_task.restart();
+ //is it for me?
+ if (n.id == MY_GROUP_ID || n.id == MY_ID) {
+ //
+ if (n.pitch < 0) n.pitch = 0;
+ volume_pin = n.pitch; //useless: for esp8266, A0 is only one adc.
+ //
+ if (n.velocity < 0) n.velocity = 0;
+ //
+ if (n.velocity == 0) {
+ //schedule 1 read
+ volume_read_task.disable();
+ volume_read_task.setIterations(1);
+ volume_read_task.restart();
+ } else {
+ // limiting max. speed.
+ if (n.velocity < 20) n.velocity = 20;
+ volume_read_task.setIterations(TASK_FOREVER);
+ volume_read_task.setInterval(n.velocity);
+ volume_read_task.restart();
+ }
+ //pull-up on/off
+ if (n.onoff == 1) {
+ volume_pullup = true; //useless: for esp8266, A0 no support for internal pull-up ?
+ } else {
+ volume_pullup = false;
+ }
}
- //pull-up on/off
- if (n.onoff == 1) {
- volume_pullup = true; //useless: for esp8266, A0 no support for internal pull-up ?
- } else {
- volume_pullup = false;
- }
- }
}
// on 'receive'
void onDataReceive(uint8_t * mac, uint8_t *incomingData, uint8_t len) {
- //
- Serial.write(incomingData, len);
-
- // open => identify => use.
- if (incomingData[0] == '{' && incomingData[len - 1] == '}' && len == (sizeof(Hello) + 2)) {
- Hello hello("");
- memcpy((uint8_t *) &hello, incomingData + 1, sizeof(Hello));
//
- Serial.println(hello.to_string());
- }
+ Serial.write(incomingData, len);
- // open => identify => use.
- if (incomingData[0] == '[' && incomingData[len - 1] == ']' && len == (sizeof(Note) + 2)) {
- Note note;
- memcpy((uint8_t *) ¬e, incomingData + 1, sizeof(Note));
- onNoteHandler(note);
- //
- Serial.println(note.to_string());
- }
+ // open => identify => use.
+ if (incomingData[0] == '{' && incomingData[len - 1] == '}' && len == (sizeof(Hello) + 2)) {
+ Hello hello("");
+ memcpy((uint8_t *) &hello, incomingData + 1, sizeof(Hello));
+ //
+ Serial.println(hello.to_string());
+ }
+
+ // open => identify => use.
+ if (incomingData[0] == '[' && incomingData[len - 1] == ']' && len == (sizeof(Note) + 2)) {
+ Note note;
+ memcpy((uint8_t *) ¬e, incomingData + 1, sizeof(Note));
+ onNoteHandler(note);
+ //
+ Serial.println(note.to_string());
+ }
}
// on 'sent'
void onDataSent(uint8_t *mac, uint8_t sendStatus) {
- char buff[256] = "";
- sprintf(buff, "Delivery failed! -> %02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
- if (sendStatus != 0) Serial.println(buff);
+ char buff[256] = "";
+ sprintf(buff, "Delivery failed! -> %02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
+ if (sendStatus != 0) Serial.println(buff);
}
//
void setup() {
- //led
- pinMode(LED_PIN, OUTPUT);
+ //led
+ pinMode(LED_PIN, OUTPUT);
- //serial
- Serial.begin(115200);
- delay(100);
+ //serial
+ Serial.begin(115200);
+ delay(100);
- //info
- Serial.println();
- Serial.println();
- Serial.println("\"hi, i m your postman.\"");
- Serial.println("-");
- Serial.println("- my id: " + String(MY_ID) + ", gid: " + String(MY_GROUP_ID) + ", call me ==> \"" + String(MY_SIGN) + "\"");
- Serial.println("- mac address: " + WiFi.macAddress() + ", channel: " + String(WIFI_CHANNEL));
- Serial.println("-");
+ //info
+ Serial.println();
+ Serial.println();
+ Serial.println("\"hi, i m your postman.\"");
+ Serial.println("-");
+ Serial.println("- my id: " + String(MY_ID) + ", gid: " + String(MY_GROUP_ID) + ", call me ==> \"" + String(MY_SIGN) + "\"");
+ Serial.println("- mac address: " + WiFi.macAddress() + ", channel: " + String(WIFI_CHANNEL));
+ Serial.println("-");
- //wifi - disabled
- system_phy_set_max_tpw(0);
- WiFiMode_t node_type = WIFI_STA;
- WiFi.mode(node_type);
+ //wifi - disabled
+ system_phy_set_max_tpw(0);
+ WiFiMode_t node_type = WIFI_STA;
+ WiFi.mode(node_type);
- //esp-now
- if (esp_now_init() != 0) {
- Serial.println("Error initializing ESP-NOW");
- return;
- }
- esp_now_set_self_role(ESP_NOW_ROLE_COMBO);
- esp_now_register_send_cb(onDataSent);
- esp_now_register_recv_cb(onDataReceive);
- //
- Serial.println("- ! (esp_now_add_peer) ==> add a 'broadcast peer' (FF:FF:FF:FF:FF:FF).");
- uint8_t broadcastmac[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
- esp_now_add_peer(broadcastmac, ESP_NOW_ROLE_COMBO, 1, NULL, 0);
+ //esp-now
+ if (esp_now_init() != 0) {
+ Serial.println("Error initializing ESP-NOW");
+ return;
+ }
+ esp_now_set_self_role(ESP_NOW_ROLE_COMBO);
+ esp_now_register_send_cb(onDataSent);
+ esp_now_register_recv_cb(onDataReceive);
+ //
+ Serial.println("- ! (esp_now_add_peer) ==> add a 'broadcast peer' (FF:FF:FF:FF:FF:FF).");
+ uint8_t broadcastmac[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
+ esp_now_add_peer(broadcastmac, ESP_NOW_ROLE_COMBO, 1, NULL, 0);
- Serial.println("-");
- Serial.println("\".-.-.-. :)\"");
- Serial.println();
+ Serial.println("-");
+ Serial.println("\".-.-.-. :)\"");
+ Serial.println();
}
void loop() {
- //
- runner.execute();
- //
+ //
+ runner.execute();
+ //
}
diff --git a/faa_volume/sketch.yaml b/faa_volume/sketch.yaml
new file mode 100644
index 0000000..ee52428
--- /dev/null
+++ b/faa_volume/sketch.yaml
@@ -0,0 +1,2 @@
+default_fqbn: esp8266:esp8266:nodemcuv2:baud=460800
+default_port: /dev/tty.SLAB_USBtoUART