added @thunder

This commit is contained in:
Dooho Yi 2025-06-30 22:22:35 +09:00
parent fe4b1f120b
commit 31bebeee13
3 changed files with 240 additions and 2 deletions

View file

@ -22,8 +22,8 @@
//============<identities>============
//
#define MY_GROUP_ID (10000)
#define MY_ID (MY_GROUP_ID + 5)
#define MY_GROUP_ID (898989)
#define MY_ID (MY_GROUP_ID + 0)
#define MY_SIGN ("@POSTMAN|@SAMPLER")
#define ADDRESSBOOK_TITLE ("broadcast only")
//
@ -252,6 +252,12 @@ void onDataReceive(uint8_t * mac, uint8_t *incomingData, uint8_t len) {
// .substring(7, 8);
char letter_outro[POST_BUFF_LEN] = "................................";
if (note.pitch < 0) note.pitch = 0;
if (note.pitch >= 1000) note.pitch = 999;
if (note.velocity < 0) note.velocity = 0;
if (note.velocity >= 1000) note.velocity = 999;
if (note.onoff < 0) note.onoff = 0;
if (note.onoff >= 10) note.onoff = 9;
sprintf(letter_outro, "[%03d%03d%01d.......................]",
(int32_t)note.pitch,
(int32_t)note.velocity,

28
@thunder/platformio.ini Normal file
View file

@ -0,0 +1,28 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[platformio]
default_envs = teensy35
[common]
lib_deps =
721 ; TaskScheduler
[env:teensy35]
platform = teensy
board = teensy35
framework = arduino
lib_deps = ${common.lib_deps}
[env:teensy36]
platform = teensy@3.6.0
board = teensy36
framework = arduino
lib_deps = ${common.lib_deps}

204
@thunder/src/main.cpp Normal file
View file

@ -0,0 +1,204 @@
//
// wirelessly connected cloud (based on ESP-NOW, a kind of LPWAN?)
//
//
// Conversation about the ROOT @ SEMA storage, Seoul
//
//
// 2021 02 15
//
// (part-3) teensy35 : 'client:sampler' (mesh post --> play sounds)
//
#include <Arduino.h>
//teensy audio
#include <Audio.h>
#include <Wire.h>
// #include <SPI.h>
// #include <SD.h>
#include <SerialFlash.h>
// GUItool: begin automatically generated code
AudioSynthWaveformSine sine1; //xy=297,249
AudioAmplifier amp1; //xy=476,249
AudioOutputAnalogStereo dacs1; //xy=663,247
AudioConnection patchCord1(sine1, amp1);
AudioConnection patchCord2(amp1, 0, dacs1, 0);
AudioConnection patchCord3(amp1, 0, dacs1, 1);
// GUItool: end automatically generated code
//task
#include <TaskScheduler.h>
Scheduler runner;
//on 'rrrrr'
extern Task rrrrr_task;
// make a rrrrr noise sequence
bool rrrrr_new = false;
void rrrrr() {
static int rrrrr_freq = 5;
static int rrrrr_amp = 100;
static int rrrrr_count = 0;
//
Serial.println("rrrrr");
if (rrrrr_new == true) {
Serial.println("rrrrr new");
rrrrr_new = false;
rrrrr_count = 0;
}
switch(random(5))
{
case 0:
rrrrr_freq = 5;
rrrrr_amp = 2000;
break;
case 1:
rrrrr_freq = 8;
rrrrr_amp = 1500;
break;
case 2:
rrrrr_freq = 10;
rrrrr_amp = 1500;
break;
case 3:
rrrrr_freq = 15;
rrrrr_amp = 1200;
break;
case 4:
rrrrr_freq = 20;
rrrrr_amp = 350;
break;
default:
;
}
//
if (rrrrr_count == 24) {
sine1.frequency(0);
amp1.gain(1);
}
else {
sine1.frequency(rrrrr_freq);
amp1.gain(rrrrr_amp);
rrrrr_task.restartDelayed(random(100, 1000));
}
rrrrr_count++;
Serial.println(rrrrr_count);
}
Task rrrrr_task(0, TASK_ONCE, &rrrrr, &runner); // this will automatically retrigger itself 24 times with randomized intervals.
//i2c
#include <Wire.h>
#include "../../post.h"
void receiveEvent(int numBytes) {
//numBytes : how many bytes received(==available)
static char letter_intro[POST_BUFF_LEN] = "................................";
// Serial.println("[i2c] on receive!");
int nb = Wire.readBytes(letter_intro, POST_LENGTH);
if (POST_LENGTH == nb) {
//convert to String
String msg = String(letter_intro);
Serial.println(msg);
//parse letter string.
// letter frame ( '[' + 30 bytes + ']' )
// : [123456789012345678901234567890]
// 'MIDI' letter frame
// : [123456789012345678901234567890]
// : [KKKVVVG.......................]
// : KKK - Key
// .substring(1, 4);
// : VVV - Velocity (volume/amp.)
// .substring(4, 7);
// : G - Gate (note on/off)
// .substring(7, 8);
String str_key = msg.substring(1, 4);
String str_velocity = msg.substring(4, 7);
String str_gate = msg.substring(7, 8);
// Serial.println(str_key);
// Serial.println(str_velocity);
// Serial.println(str_gate);
//
int key = str_key.toInt(); // pitch: 0 ~ 999
//
int velocity = str_velocity.toInt(); // amp: 0 ~ 999
//
int gate = str_gate.toInt(); // gate: 0 ~ 9
//on 'rrrrr'
if (gate == 2) {
rrrrr_new = true;
rrrrr_task.restart();
}
//on 'single note'
else if (gate == 1) {
float amp_gain = (float)velocity / 500.0; // amp: 0 ~ 2.0
float sine_freq = key;
//
sine1.frequency(sine_freq);
amp1.gain(amp_gain);
}
//on 'stop all note'
else if (gate == 0) {
sine1.frequency(0);
amp1.gain(0);
//
rrrrr_task.disable();
}
}
}
void setup() {
//serial monitor
Serial.begin(115200);
//
delay(50);
// <-- strange? but, this was needed !!
// w/o ==> get killed by watchdog.. :(
//
// while (!Serial) {}
// --> enable this.. to use Serial. otherwise, very jerky/unstable..
// --> and disable this.. if there is no Serial connection! otherwise, brd won't start.
//i2c
Wire.begin(I2C_ADDR);
Wire.onReceive(receiveEvent);
// DISABLED.. due to bi-directional I2C hardship. ==> use UART.
// Wire.onRequest(requestEvent);
//audio
AudioMemory(20);
//
sine1.frequency(0);
sine1.amplitude(1.0);
//
amp1.gain(1.0);
//led
pinMode(13, OUTPUT);
digitalWrite(13, LOW); // LOW: OFF
//
Serial.println("[setup] done.");
}
void loop() {
runner.execute();
}