Skip to content

Instantly share code, notes, and snippets.

@Simon-L
Last active November 19, 2017 15:26
Show Gist options
  • Save Simon-L/1a65ef1271d0c1fa44a5ebd8745558e4 to your computer and use it in GitHub Desktop.
Save Simon-L/1a65ef1271d0c1fa44a5ebd8745558e4 to your computer and use it in GitHub Desktop.
Tempo and time signature indicator with RGB LED for Bitwig Studio using Wemos D1 mini (esp8266) and Neopixel led strip.

Tempo/beat indicator with RGB LED for Bitwig Studio

Install the OSC controller script for Bitwig, see here: https://github.com/git-moss/OSC4Bitwig

Use the code below, change SSID name and password as well as led number and pin accordingly. Get the IP from the serial monitor when the ESP8266 starts.

Update IP in OSC Controller Script for sending, port is 9000. (Or change port on line 17)

Press play in Bitwig and once again watch blinking LEDs in an Arduino project!

gif

#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <OSCMessage.h>
#include <OSCBundle.h>
#include <OSCData.h>
#include "FastLED.h"
// How many leds in your strip?
#define NUM_LEDS 8
#define DATA_PIN 2
char ssid[] = "SSIDNAME"; // your network SSID (name)
char pass[] = "SSIDPASSWORD"; // your network password
// A UDP instance to let us send and receive packets over UDP
WiFiUDP Udp;
const unsigned int localPort = 9000; // local port to listen for UDP packets (here's where we send the packets)
CRGB leds[8];
OSCErrorCode error;
// string for received data
char position[13];
// temp variable
unsigned int newTick = 0;
// variable for current led number
unsigned int led = 0;
void setup() {
Serial.begin(115200);
// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Serial.println("Starting UDP");
Udp.begin(localPort);
Serial.print("Local port: ");
Serial.println(Udp.localPort());
// sanity check delay - allows reprogramming if accidently blowing power w/leds
delay(2000);
// initialize leds with FastLED
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
}
void handle(OSCMessage &msg) {
// get position from OSC packet
msg.getString(0, position, 13);
// beat position is at index 5, minus 48 to offset back to 0 (initially an ASCII number)
newTick = int(position[5]) - 48;
// change on new beat
if (newTick != led) {
Serial.println(newTick);
leds[led-1] = CRGB::Black;
// show green color for beat 1
leds[newTick-1] = newTick == 1 ? CRGB::Green : CRGB::Red;
FastLED.show();
// current variable is temp variable
led = newTick;
}
}
void loop() {
OSCBundle bundle;
int size = Udp.parsePacket();
if (size > 0) {
while (size--) {
bundle.fill(Udp.read());
}
if (!bundle.hasError()) {
// handle OSC message on /position with handle()
bundle.dispatch("/position", handle);
} else {
error = bundle.getError();
Serial.print("error: ");
Serial.println(error);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment