Skip to content

Instantly share code, notes, and snippets.

@qjarvisholland
Created June 7, 2018 01:17
Show Gist options
  • Save qjarvisholland/1f80b315c0c4134791ac34c209c9b45e to your computer and use it in GitHub Desktop.
Save qjarvisholland/1f80b315c0c4134791ac34c209c9b45e to your computer and use it in GitHub Desktop.
#include <Adafruit_NeoPixel.h>
//#include <OSCBoards.h>
#include <OSCBundle.h>
#include <OSCData.h>
#include <OSCMatch.h>
#include <OSCMessage.h>
#include <OSCTiming.h>
#include <SLIPEncodedSerial.h>
#include <SLIPEncodedUSBSerial.h>
#include <SPI.h>
#include <WiFi101.h>
#include <WiFiUdp.h>
#include <OSCMessage.h>
#define ENCODER_USE_INTERRUPTS
#define ENCODER_OPTIMIZE_INTERRUPTS
// #include <EEPROM.h>
#include <Encoder.h>
// encoder pins
Encoder rotaryEnc(11, 12);
// avoid using pins with LEDs attached
// OSC NETWORK STUFF
int status = WL_IDLE_STATUS;
char ssid[] = "****"; // your network SSID (name)
char pass[] = "****"; // your network password (use for WPA, or use as key for WEP)
//the Arduino's IP
IPAddress ip(128, 32, 122, 252);
//destination IP
IPAddress outIp(192, 168, 1, 50);
const unsigned int outPort = 9999;
WiFiUDP Udp;
void setup() {
Serial.begin(9600);
delay(5000);
while (!Serial) {
Serial.println("waiting for serial..."); // wait for serial port to connect. Needed for native USB port only
}
/*
WiFi.setPins(10, 6, 5); // CS, irq, rst
delay(5000);
Serial.println("Serial port connected");
// check for the presence of the shield:
Serial.println(WiFi.status());
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue:
// while (true);
}
Serial.println(WiFi.status());
// attempt to connect to WiFi network:
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection:
delay(10000);
}
Serial.println("Connected to wifi");
// printWiFiStatus();
Serial.println("\nStarting connection to server...");
// if you get a connection, report back via serial:
Udp.begin(outPort);
*/
Serial.print("STARTED BABY");
}
long rotaryPos = -999;
long rotaryVal = 0;
void loop() {
long newRotaryPos;
newRotaryPos = rotaryEnc.read();
if (newRotaryPos > rotaryPos) {
Serial.print("up");
Serial.print(newRotaryPos);
rotaryVal++;
// rotaryPos = newRotaryPos;
/*
//the message wants an OSC address as first argument
OSCMessage msg("rotaryup");
msg.add(2);
Udp.beginPacket(outIp, outPort);
msg.send(Udp); // send the bytes to the SLIP stream
Udp.endPacket(); // mark the end of the OSC Packet
msg.empty(); // free space occupied by message
*/
}
else if (newRotaryPos < rotaryPos) {
Serial.print("down");
Serial.print(newRotaryPos);
rotaryVal--;
/*
OSCMessage msg("rotarydown");
msg.add(-2);
Udp.beginPacket(outIp, outPort);
msg.send(Udp); // send the bytes to the SLIP stream
Udp.endPacket(); // mark the end of the OSC Packet
msg.empty(); // free space occupied by message
*/
}
rotaryPos = newRotaryPos;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment