2 dimensional + polyphonic rewrite of ringringrain. (Rev.2)

This commit is contained in:
Dooho Yi 2023-04-09 20:43:00 +09:00
parent 055bc40e37
commit edbfd0adb4
4 changed files with 511 additions and 69 deletions

View file

@ -0,0 +1 @@
src/rainboard.ino

View file

@ -1,38 +1,62 @@
//
// a 2-dimensional ringringrain touch-pad(board)
//
// D. Yi @ 2023 4 9
//
////network!
#include <ConfigurableFirmata.h> #include <ConfigurableFirmata.h>
#include <vector>
const char* ssid = "nolink2"; const char* ssid = "nolink2";
const char* password = "2222277777"; const char* password = "2222277777";
const int NETWORK_PORT = 27016; const int NETWORK_PORT = 27016;
//// A UDP instance to let us send and receive packets over UDP
//WiFiUDP Udp;
//const IPAddress outIp(192,168,43,13); // remote IP (not needed for receive)
//const unsigned int outPort = 9999; // remote port (not needed for receive)
//const unsigned int localPort = 8888; // local port to listen for UDP packets (here's where we send the packets)
#include <WiFi.h> #include <WiFi.h>
#include "utility/WiFiClientStream.h" #include "utility/WiFiClientStream.h"
#include "utility/WiFiServerStream.h" #include "utility/WiFiServerStream.h"
WiFiServerStream serverStream(NETWORK_PORT); WiFiServerStream serverStream(NETWORK_PORT);
std::vector<int> pins = {16, 15, 17, 18, 20, 19, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33}; //16 ////pad structure
//2 ==> flipping autonomously 1/0 without grounding! (maybe grounded by something else???)
//1, 3, 4, 5, 6, 7, 8, ==> flipping 1/0 ... while grounded manually.
//i have a feeling ... this relates to 'touch sensing'... this precise flipping might be from cap. charge/discharge cycles? #define NUMKEYS 42 // columns : 14, rows : 3
// --> how many keys are available for this pad
int keystat[NUMKEYS] = {0, };
// --> a buffer to store statuses of all keys
// --> needed to extract only 'the change' of key statuses
#define MAXCHANGES 10
int keychanges[MAXCHANGES] = {0, };
int n_keychg = 0;
// --> for monitoring only 'changed' keys.
#define NUMCOLS 14
int pins_cols[NUMCOLS] = {19, 20, 18, 17, 15, 16, 40, 39, 38, 37, 36, 35, 34, 33}; //16
// --> cols is horizontal offsets on the board
// --> to be read as input.
#define NUMROWS 3
int pins_rows[NUMROWS] = {6, 7, 8};
// --> rows is vertical offsets on the board
// --> to be driven as output.
void setup() void setup()
{ {
//pinmodes
for (int idx = 0; idx < pins.size(); idx++) {
pinMode(pins[idx], INPUT_PULLUP);
}
//serial //serial
Serial.begin(115200); Serial.begin(115200);
//pinmodes
// rows : to be driven as output. (scanning)
for (int idx = 0; idx < NUMROWS; idx++) {
pinMode(pins_rows[idx], OUTPUT);
digitalWrite(pins_rows[idx], HIGH);
}
// cols : to be read as input. (PULL-UP)
for (int idx = 0; idx < NUMCOLS; idx++) {
pinMode(pins_cols[idx], INPUT_PULLUP);
}
//wifi //wifi
WiFi.mode(WIFI_STA); WiFi.mode(WIFI_STA);
// Connect to WiFi network // Connect to WiFi network
@ -55,63 +79,76 @@ void setup()
//firmata //firmata
Firmata.disableBlinkVersion(); Firmata.disableBlinkVersion();
Firmata.begin(serverStream); Firmata.begin(serverStream);
// Firmata.begin(115200);
// Firmata.setFirmwareNameAndVersion("ConfigurableFirmata", FIRMATA_FIRMWARE_MAJOR_VERSION, FIRMATA_FIRMWARE_MINOR_VERSION);
} }
void loop() void loop()
{ {
for (int idx = 0; idx < pins.size(); idx++) { // perform a full scan of the key statuses!
Firmata.sendAnalog(idx, digitalRead(pins[idx])*1023);
// update row voltages
static int row = 0;
digitalWrite(pins_rows[row], HIGH); // let old 'on' row goes 'off' first.
row++;
if (row >= NUMROWS) {
row = 0;
} }
digitalWrite(pins_rows[row], LOW); // let new 'off' row goes 'on'.. -> ready to scan.
// 100us ~ 200us, waiting for the electricity ready...
delayMicroseconds(200);
// read all cols
for (int col = 0; col < NUMCOLS; col++) {
int key = row * NUMCOLS + col;
if (key < NUMKEYS) {
int cur_key = !digitalRead(pins_cols[col]); //logic inversion. (HIGH = noteoff, LOW = noteon.)
// if it is 'changed',
if (cur_key != keystat[key]) {
// if there is a room to record this change,
if (n_keychg < MAXCHANGES) {
// make a memo.
int keycoded = (key) * 10 + cur_key; // for example : C4 note-on --> 601 ( == 60*10 + 1)
keychanges[n_keychg] = keycoded;
n_keychg++;
// send Firmata msg. over WIFI.
Firmata.sendAnalog(0, keycoded);
//@Pd
//[pduino/arduino] will divide this by 1023.0 to map 0-1023 -> 0.0-1.0
//so, to recover original values, multiply back by 1023.0.
}
}
// okay. good. now, apply the change.
keystat[key] = cur_key;
}
}
// at the moment of 'full scan done'
if (row == NUMROWS - 1) {
// // print out the buffer status.
// for (int key = 0; key < NUMKEYS; key++) {
// Serial.print(keystat[key]); Serial.print(" ");
// }
// Serial.println();
// // print out the changes.
// for (int chg = 0; chg < n_keychg; chg++) {
// Serial.print(keychanges[chg]);
// Serial.println();
// }
// clear 'keychanges' array
for (int idx = 0; idx < MAXCHANGES; idx++) {
keychanges[idx] = 0;
n_keychg = 0;
}
}
//
// // discard all incoming MIDI msgs.
// while (usbMIDI.read()) { }
serverStream.maintain(); serverStream.maintain();
} }
// [NOTE]
// because firmata analog way has limits of max. channels <= 16. you can use digital way.. like below.
// but this not yet confirmed whether it is working or not.
//
// #include <ConfigurableFirmata.h>
// int pins_port0[8] = {17, 18, 2, 3, 4, 5, 6, 7};
// int pins_port1[8] = {8, 9, 10, 11, 12, 24, 25, 26};
// int pins_port2[8] = {27, 28, 29, 30, 31, 32, 33, 33};
// void setup()
// {
// for (int idx = 0; idx < 8; idx++) pinMode(pins_port0[idx], INPUT_PULLUP);
// for (int idx = 0; idx < 8; idx++) pinMode(pins_port1[idx], INPUT_PULLUP);
// for (int idx = 0; idx < 8; idx++) pinMode(pins_port2[idx], INPUT_PULLUP);
// Firmata.setFirmwareNameAndVersion("ConfigurableFirmata", FIRMATA_FIRMWARE_MAJOR_VERSION, FIRMATA_FIRMWARE_MINOR_VERSION);
// Firmata.begin(115200);
// }
// void loop()
// {
// byte port = 0;
// static byte port0_prev = 0;
// port = 0x00;
// for (int idx = 0; idx < 8; idx++) port |= (digitalRead(pins_port0[idx]) ? 0x01<<idx : 0x00);
// if (port0_prev != port) Firmata.sendDigitalPort(0, port);
// port0_prev = port;
// static byte port1_prev = 0;
// port = 0x00;
// for (int idx = 0; idx < 8; idx++) port |= (digitalRead(pins_port1[idx]) ? 0x01<<idx : 0x00);
// if (port1_prev != port) Firmata.sendDigitalPort(1, port);
// port1_prev = port;
// static byte port2_prev = 0;
// port = 0x00;
// for (int idx = 0; idx < 8; idx++) port |= (digitalRead(pins_port2[idx]) ? 0x01<<idx : 0x00);
// if (port2_prev != port) Firmata.sendDigitalPort(2, port);
// port2_prev = port;
// delay(20);
// }

View file

@ -0,0 +1,26 @@
#N canvas 750 349 450 322 12;
#X obj 25 192 *~;
#X obj 25 223 dac~;
#X obj 25 116 mtof;
#X obj 25 141 osc~;
#X obj 112 141 * 0.05;
#X obj 112 172 mavg 25;
#X obj 25 22 inlet;
#X obj 25 47 unpack f f;
#X obj 112 78 resample 100;
#X obj 92 225 env~;
#X floatatom 92 250 5 0 0 0 - - - 0;
#X obj 186 141 outlet;
#X connect 0 0 1 0;
#X connect 0 0 1 1;
#X connect 0 0 9 0;
#X connect 2 0 3 0;
#X connect 3 0 0 0;
#X connect 4 0 5 0;
#X connect 5 0 0 1;
#X connect 6 0 7 0;
#X connect 7 0 2 0;
#X connect 7 1 8 0;
#X connect 8 0 4 0;
#X connect 8 0 11 0;
#X connect 9 0 10 0;

378
ringringrain_rev2.pd Normal file
View file

@ -0,0 +1,378 @@
#N canvas 0 33 1016 615 10;
#X obj 597 87 loadbang;
#N canvas 0 22 450 300 (subpatch) 0;
#X array raining 2.57403e+06 float 0;
#X coords 0 0.3 2.57403e+06 -0.3 100 200 1 0 0;
#X restore 870 87 graph;
#X floatatom 597 374 0 0 0 0 - - - 0;
#X obj 597 144 soundfiler;
#X floatatom 597 167 0 0 0 0 - - - 0;
#X obj 597 348 env~ 16384;
#X obj 739 399 *~;
#X obj 739 438 hip~ 5;
#X msg 612 291 bang;
#X obj 690 338 bng 15 250 50 0 empty empty empty 17 7 0 10 #fcfcfc
#000000 #000000;
#X obj 597 193 bng 15 250 50 0 empty empty empty 17 7 0 10 #fcfcfc
#000000 #000000;
#X floatatom 754 349 5 0 0 0 - - - 0;
#X obj 612 217 delay 2000;
#X obj 612 241 bng 15 250 50 0 empty empty empty 17 7 0 10 #fcfcfc
#000000 #000000;
#X obj 740 518 dac~;
#N canvas 0 22 450 300 pan 0;
#X obj 59 82 f 1;
#X obj 59 106 -;
#X obj 95 129 *;
#X obj 44 130 *;
#X obj 44 36 inlet;
#X obj 110 36 inlet;
#X obj 44 171 outlet;
#X obj 95 171 outlet;
#X connect 0 0 1 0;
#X connect 1 0 3 1;
#X connect 2 0 7 0;
#X connect 3 0 6 0;
#X connect 4 0 0 0;
#X connect 4 0 3 0;
#X connect 4 0 2 0;
#X connect 5 0 1 1;
#X connect 5 0 2 1;
#X restore 394 561 pd pan;
#X obj 739 488 *~;
#X obj 772 488 *~;
#X obj 458 453 snapshot~;
#X floatatom 533 493 5 0 0 0 - - - 0;
#X obj 341 388 bng 15 250 50 0 empty empty empty 17 7 0 10 #fcfcfc
#000000 #000000;
#X obj 465 396 +~ 1;
#X obj 465 423 *~ 0.5;
#X obj 465 368 osc~ 0.1;
#X obj 462 492 s pann;
#X obj 432 530 r pann;
#X obj 341 413 metro 200;
#X msg 384 506 1;
#X obj 754 375 * 6;
#X obj 803 417 bng 15 250 50 0 empty empty empty 17 7 0 10 #fcfcfc
#000000 #000000;
#X msg 803 437 1;
#X text 6 7 .;
#X text 374 102 dsp ON/OFF;
#X floatatom 358 147 5 0 0 0 - - - 0;
#X text 395 148 % cpu;
#X obj 358 125 dsp;
#X obj 358 102 tgl 15 0 empty empty empty 8 -8 0 10 #fcfcfc #000000
#000000 0 1;
#X obj 358 56 loadbang;
#X text 356 30 Automatically turn on audio;
#X text 356 40 8 seconds after patch opens.;
#X obj 358 79 delay 8000;
#X text 35 13 arduino i/f;
#X text 602 28 sound generators - sample sound;
#X obj 447 106 print dsp_bang;
#X obj 358 171 print dsp_load;
#X obj 26 68 arduino-wifi;
#X msg 146 78 disconnect;
#X obj 95 105 tgl 15 0 empty empty connected? 17 7 0 10 #fcfcfc #000000
#000000 0 1;
#X msg 107 43 connect 192.168.10.113 27016;
#X obj 26 126 route analog;
#X obj 26 149 route 0;
#X obj 26 172 * 1023;
#X obj 26 195 t a a;
#X obj 26 218 / 10;
#X obj 26 241 int;
#X obj 71 218 mod 10;
#X obj 71 241 int;
#X obj 26 294 pack f f;
#X text 260 283 60 == C4 == 261.63hz;
#X obj 156 323 clone ringringrain_piano_node 10;
#X obj 26 264 + 60;
#X obj 156 294 pack f f f;
#X obj 156 271 - 1;
#X msg 156 203 stop;
#X obj 26 323 print notes;
#X obj 156 431 tabwrite hands;
#X obj 156 362 unpack f f;
#X obj 156 408 f;
#X obj 156 385 t b a;
#X obj 118 171 r keyhands;
#N canvas 502 134 450 364 coundhands 0;
#X obj 152 113 until;
#X obj 152 156 f;
#X obj 182 156 + 1;
#X floatatom 152 182 5 0 0 0 - - - 0;
#X obj 182 267 +;
#X obj 152 267 f;
#X obj 152 238 t b a;
#X obj 117 217 bng 15 250 50 0 empty empty empty 17 7 0 10 #fcfcfc
#000000 #000000;
#X msg 199 113 0;
#X obj 152 72 t b a b;
#X msg 152 49 10;
#X obj 152 215 tabread hands;
#X obj 228 21 table hands 10;
#X obj 18 65 metro 100;
#X obj 18 45 tgl 15 0 empty empty empty 17 7 0 10 #fcfcfc #000000 #000000
0 1;
#X obj 117 285 f;
#X obj 18 22 loadbang;
#X floatatom 117 308 5 0 0 0 - - - 0;
#X obj 117 330 outlet;
#X connect 0 0 1 0;
#X connect 1 0 2 0;
#X connect 1 0 3 0;
#X connect 2 0 1 1;
#X connect 3 0 11 0;
#X connect 4 0 5 1;
#X connect 5 0 4 0;
#X connect 5 0 15 1;
#X connect 6 0 5 0;
#X connect 6 1 4 1;
#X connect 7 0 15 0;
#X connect 8 0 1 1;
#X connect 8 0 5 1;
#X connect 9 0 7 0;
#X connect 9 1 0 0;
#X connect 9 2 8 0;
#X connect 10 0 9 0;
#X connect 11 0 6 0;
#X connect 13 0 10 0;
#X connect 14 0 13 0;
#X connect 15 0 17 0;
#X connect 16 0 14 0;
#X connect 17 0 18 0;
#X restore 754 260 pd coundhands;
#X floatatom 754 283 5 0 0 1 hands - - 0;
#X msg 597 115 read -resize Rain1.wav raining;
#X msg 597 262 set raining;
#X obj 597 316 tabplay~ raining;
#X obj 754 321 mavg 120;
#X obj 803 394 loadbang;
#N canvas 474 285 719 481 keyhands 0;
#X obj 180 18 key;
#X floatatom 180 41 5 0 0 0 - - - 0;
#X obj 180 63 route 97 115 100 102 103 104 106 107 108 59 113 119 101
114 116 121 117, f 71;
#X msg 177 91 2;
#X msg 207 95 3;
#X msg 237 91 4;
#X msg 267 95 5;
#X msg 297 91 6;
#X msg 327 95 7;
#X msg 357 91 8;
#X msg 387 95 9;
#X msg 417 91 10;
#X msg 447 95 11;
#X msg 477 91 12;
#X msg 507 95 14;
#X msg 537 91 15;
#X msg 567 95 16;
#X msg 597 91 17;
#X msg 627 95 18;
#X msg 657 91 19;
#X listbox 308 316 6 0 0 1 simulated!? - - 0;
#X floatatom 180 161 5 0 0 0 - - - 0;
#X obj 180 183 route 97 115 100 102 103 104 106 107 108 59 113 119
101 114 116 121 117, f 71;
#X msg 177 211 2;
#X msg 207 215 3;
#X msg 237 211 4;
#X msg 267 215 5;
#X msg 297 211 6;
#X msg 327 215 7;
#X msg 357 211 8;
#X msg 387 215 9;
#X msg 417 211 10;
#X msg 447 215 11;
#X msg 477 211 12;
#X msg 507 215 14;
#X msg 537 211 15;
#X msg 567 215 16;
#X msg 597 211 17;
#X msg 627 215 18;
#X msg 657 211 19;
#X obj 180 138 keyup;
#X obj 37 192 loadbang;
#X msg 360 142 \$1 1;
#X msg 407 268 \$1 0;
#X obj 308 338 unpack;
#X obj 308 361 * 10;
#X obj 308 384 +;
#X floatatom 308 407 5 0 0 0 - - - 0;
#X obj 308 429 s keyhands;
#X connect 0 0 1 0;
#X connect 1 0 2 0;
#X connect 2 0 3 0;
#X connect 2 1 4 0;
#X connect 2 2 5 0;
#X connect 2 3 6 0;
#X connect 2 4 7 0;
#X connect 2 5 8 0;
#X connect 2 6 9 0;
#X connect 2 7 10 0;
#X connect 2 8 11 0;
#X connect 2 9 12 0;
#X connect 2 10 13 0;
#X connect 2 11 14 0;
#X connect 2 12 15 0;
#X connect 2 13 16 0;
#X connect 2 14 17 0;
#X connect 2 15 18 0;
#X connect 2 16 19 0;
#X connect 3 0 42 0;
#X connect 4 0 42 0;
#X connect 5 0 42 0;
#X connect 6 0 42 0;
#X connect 7 0 42 0;
#X connect 8 0 42 0;
#X connect 9 0 42 0;
#X connect 10 0 42 0;
#X connect 11 0 42 0;
#X connect 12 0 42 0;
#X connect 13 0 42 0;
#X connect 14 0 42 0;
#X connect 15 0 42 0;
#X connect 16 0 42 0;
#X connect 17 0 42 0;
#X connect 18 0 42 0;
#X connect 19 0 42 0;
#X connect 20 0 44 0;
#X connect 21 0 22 0;
#X connect 22 0 23 0;
#X connect 22 1 24 0;
#X connect 22 2 25 0;
#X connect 22 3 26 0;
#X connect 22 4 27 0;
#X connect 22 5 28 0;
#X connect 22 6 29 0;
#X connect 22 7 30 0;
#X connect 22 8 31 0;
#X connect 22 9 32 0;
#X connect 22 10 33 0;
#X connect 22 11 34 0;
#X connect 22 12 35 0;
#X connect 22 13 36 0;
#X connect 22 14 37 0;
#X connect 22 15 38 0;
#X connect 22 16 39 0;
#X connect 23 0 43 0;
#X connect 24 0 43 0;
#X connect 25 0 43 0;
#X connect 26 0 43 0;
#X connect 27 0 43 0;
#X connect 28 0 43 0;
#X connect 29 0 43 0;
#X connect 30 0 43 0;
#X connect 31 0 43 0;
#X connect 32 0 43 0;
#X connect 33 0 43 0;
#X connect 34 0 43 0;
#X connect 35 0 43 0;
#X connect 36 0 43 0;
#X connect 37 0 43 0;
#X connect 38 0 43 0;
#X connect 39 0 43 0;
#X connect 40 0 21 0;
#X connect 41 0 23 0;
#X connect 41 0 39 0;
#X connect 41 0 38 0;
#X connect 41 0 37 0;
#X connect 41 0 36 0;
#X connect 41 0 35 0;
#X connect 41 0 34 0;
#X connect 41 0 33 0;
#X connect 41 0 32 0;
#X connect 41 0 31 0;
#X connect 41 0 30 0;
#X connect 41 0 29 0;
#X connect 41 0 28 0;
#X connect 41 0 27 0;
#X connect 41 0 26 0;
#X connect 41 0 25 0;
#X connect 41 0 24 0;
#X connect 42 0 20 0;
#X connect 43 0 20 0;
#X connect 44 0 45 0;
#X connect 44 1 46 1;
#X connect 45 0 46 0;
#X connect 46 0 47 0;
#X connect 47 0 48 0;
#X restore 200 130 pd keyhands simulator;
#X msg 814 344 1;
#X obj 156 248 poly 10;
#X connect 0 0 72 0;
#X connect 3 0 4 0;
#X connect 4 0 10 0;
#X connect 5 0 2 0;
#X connect 6 0 7 0;
#X connect 7 0 16 0;
#X connect 7 0 17 0;
#X connect 8 0 74 0;
#X connect 9 0 74 0;
#X connect 10 0 73 0;
#X connect 10 0 12 0;
#X connect 11 0 28 0;
#X connect 12 0 13 0;
#X connect 13 0 8 0;
#X connect 16 0 14 0;
#X connect 17 0 14 1;
#X connect 18 0 19 0;
#X connect 18 0 24 0;
#X connect 20 0 26 0;
#X connect 21 0 22 0;
#X connect 22 0 18 0;
#X connect 23 0 21 0;
#X connect 25 0 15 1;
#X connect 26 0 18 0;
#X connect 26 0 27 0;
#X connect 27 0 15 0;
#X connect 28 0 6 1;
#X connect 29 0 30 0;
#X connect 30 0 16 1;
#X connect 30 0 17 1;
#X connect 35 0 33 0;
#X connect 36 0 35 0;
#X connect 37 0 40 0;
#X connect 40 0 36 0;
#X connect 40 0 43 0;
#X connect 45 0 49 0;
#X connect 45 1 47 0;
#X connect 46 0 45 1;
#X connect 48 0 45 1;
#X connect 49 0 50 0;
#X connect 50 0 51 0;
#X connect 51 0 52 0;
#X connect 52 0 53 0;
#X connect 52 1 55 0;
#X connect 53 0 54 0;
#X connect 54 0 60 0;
#X connect 55 0 56 0;
#X connect 56 0 57 1;
#X connect 57 0 64 0;
#X connect 57 0 79 0;
#X connect 59 0 66 0;
#X connect 60 0 57 0;
#X connect 61 0 59 0;
#X connect 62 0 61 0;
#X connect 63 0 79 0;
#X connect 66 0 68 0;
#X connect 66 1 67 1;
#X connect 67 0 65 0;
#X connect 68 0 67 0;
#X connect 68 1 65 1;
#X connect 69 0 52 0;
#X connect 70 0 71 0;
#X connect 71 0 75 0;
#X connect 72 0 3 0;
#X connect 73 0 74 0;
#X connect 74 0 5 0;
#X connect 74 0 6 0;
#X connect 74 1 9 0;
#X connect 75 0 11 0;
#X connect 76 0 29 0;
#X connect 78 0 75 0;
#X connect 79 0 62 0;
#X connect 79 1 61 1;
#X connect 79 2 61 2;
#X coords 0 0 1 1 85 60 0;