Created
June 8, 2018 00:55
-
-
Save qjarvisholland/26a36edb6babff56f956238abe8badfb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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[] = "PaulSwift"; // your network SSID (name) | |
char pass[] = "thankyou"; // your network password (use for WPA, or use as key for WEP) | |
//the Arduino's IP (only for recieving) | |
// IPAddress ip(128, 32, 122, 252); | |
//destination IP | |
IPAddress outIp1(192, 168, 1, 6); | |
IPAddress outIp2(192, 168, 1, 10); | |
IPAddress outIp3(192, 168, 1, 11); | |
const unsigned int outPort = 9999; | |
WiFiUDP Udp; | |
void setup() { | |
digitalWrite(2, HIGH); | |
Serial.begin(9600); | |
delay(200); | |
// while (!Serial) { | |
// Serial.println("waiting for serial..."); // wait for serial port to connect. Needed for native USB port only | |
// } | |
WiFi.setPins(8, 7, 4); // CS, irq, rst | |
delay(1000); | |
// 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 3 seconds for connection: | |
delay(2000); | |
} | |
// Serial.println("Connected to wifi"); | |
// printWiFiStatus(); | |
// Serial.println("\nStarting connection to server..."); | |
// if you get a connection, report back via serial: | |
Udp.begin(outPort); | |
//connection successful code (blink LED x3) | |
digitalWrite(13) HIGH; | |
delay(30); | |
digitalWrite(13) LOW; | |
delay(10); | |
digitalWrite(13) HIGH; | |
delay(30); | |
digitalWrite(13) LOW; | |
delay(10); | |
digitalWrite(13) HIGH; | |
delay(30); | |
digitalWrite(13) LOW; | |
// 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; | |
delay(10); | |
//the message wants an OSC address as first argument | |
OSCMessage msg("/rotary"); | |
msg.add(2); | |
Udp.beginPacket(outIp1, outPort); | |
msg.send(Udp); // send the bytes to the SLIP stream | |
Udp.endPacket(); // mark the end of the OSC Packet | |
Udp.beginPacket(outIp3, 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--; | |
delay(10); | |
OSCMessage msg("/rotary"); | |
msg.add(-2); | |
Udp.beginPacket(outIp1, outPort); | |
msg.send(Udp); // send the bytes to the SLIP stream | |
Udp.endPacket(); // mark the end of the OSC Packet | |
Udp.beginPacket(outIp3, 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; | |
delay(10); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment