diff --git a/esp32_vroom_38pin/esp32_vroom_38pin.ino b/esp32_vroom_38pin/esp32_vroom_38pin.ino new file mode 100644 index 0000000..13ba1fc --- /dev/null +++ b/esp32_vroom_38pin/esp32_vroom_38pin.ino @@ -0,0 +1,200 @@ +// esp32 capacitive touch interface ///////////////////////////////////////////////// +// rob canning 2023 ///////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////// +// flash mode changed to DIO !!! +// NEOPIXEL //////////////////////////////////////////////////// +#include // https://github.com/kitesurfer1404/WS2812FX + +// On the ESP32S2 SAOLA GPIO is the NeoPixel. +#define PIN 25 +//Single NeoPixel + +WS2812FX ws2812fx = WS2812FX(12, PIN, NEO_GRB + NEO_KHZ800); + +#define DELAYVAL 25 // Time (in milliseconds) to pause between color change +//#include // Serial Peripheral Interface + +// MPR121 ///////////////////////////////////////////////////// +#include // allows you to communicate with I2C / TWI devices +#include + +#ifndef _BV +#define _BV(bit) (1 << (bit)) +#endif +// You can have up to 4 on one i2c bus but one is enough for testing! +Adafruit_MPR121 cap0 = Adafruit_MPR121(); +Adafruit_MPR121 cap1 = Adafruit_MPR121(); + +// Keeps track of the last pins touched +// so we know when buttons are 'released' +uint16_t lasttouched[2]; +uint16_t currtouched[2]; + +// Wi-Fi SETTINGS ///////////// + +#include +const char* ssid = "zavod rizoma"; +const char* password = "cermozise"; +// BROADCAST TO ALL IP / port +const IPAddress castIp = IPAddress(192,168,0,255); // 255 FOR BROADCAST +const int port = 57120; // SUPERCOLLIDERS DEFAULT INCOMING OSC PORT +bool connected = false; +#include +WiFiUDP udp; + +// OSC and serial communications //////////////////////////// + +#define SERIAL_OSC +#define WIFI_OSC +#include +#include +#include +/* OSC MSG channels */ +OSCBundle bundle; + +// SERIAL ///////////////////////////////// +#ifdef BOARD_HAS_USB_SERIAL +#include +SLIPEncodedUSBSerial SLIPSerial( thisBoardsSerialUSB ); +#else +#include +SLIPEncodedSerial SLIPSerial(Serial); +#endif + + +/////////////////////////////////////////// + +byte KEYLEN = 12; + +void setup() { + ws2812fx.init(); + ws2812fx.setBrightness(10); + + // parameters: index, start, stop, mode, color, speed, reverse + ws2812fx.setSegment(0, 0, 11, FX_MODE_BREATH, 0xFFFFFF, 1000, false); // segment 0 is leds 0 - 9 + //ws2812fx.setSegment(1, 0, 0, FX_MODE_BREATH, 0xFF0000, 300, false); // segment 1 is leds 10 - 19 + //ws2812fx.setSegment(2, 6, 11, FX_MODE_BREATH, 0x0000FF, 400, true); // segment 2 is leds 20 - 29 + + ws2812fx.start(); + + Serial.begin(115200); + WiFi.mode(WIFI_AP); + connectWiFi(); + + const String macAddress = WiFi.macAddress(); ; + + // Default address is 0x5A, if tied to 3.3V its 0x5B + // If tied to SDA its 0x5C and if SCL then 0x5D + if (!cap0.begin(0x5A)) { + Serial.println("MPR121 A not found, check wiring?"); + while (1); + } Serial.println("MPR121 A found!"); + + + if (!cap1.begin(0x5C)) { + Serial.println("MPR121 B not found, check wiring?"); + while (1); + } Serial.println("MPR121 B found!"); + + +//cap0.setThreshholds(20, 6); +//cap1.setThreshholds(20, 6); + +#ifdef SERIAL_OSC + SLIPSerial.begin(115200); // set this as high as you can reliably run on your platform +#endif + +} // setup ends ////////////////////////////////////////////////// + + +// MAIN LOOP ///////////////////////////////////////////////////////// + +int colorCount = 0; + + +void loop() { + ws2812fx.service(); + sendCapacitive(cap0, 0); // from the 121 + sendCapacitive(cap1, 1); // from the 121 +} + +// FUNCTIONS ///////////////////////////////////////////// + +void connectWiFi(){ + // Connect to Wi-Fi network with SSID and password + Serial.print("Connecting to "); + Serial.println(ssid); + WiFi.begin(ssid, password); + while (WiFi.status() != WL_CONNECTED) { + ws2812fx.setPixelColor(0, ws2812fx.Color(0,3,222)); + delay(500); + Serial.print("."); + } + + // Print local IP address and start web server + // Serial.println(""); + Serial.println("WiFi connected."); + Serial.println("IP address: "); + Serial.println(WiFi.localIP()); +} + +// detect touch events and send over OSC ////////////// + +void sendCapacitive(Adafruit_MPR121 sensorboard, int index){ + // Get the currently touched pads + currtouched[index] = sensorboard.touched() ; + + for (uint8_t i=0; i