Last active
May 16, 2019 15:08
-
-
Save dropmeaword/bd198e08aeb57fbcff6b4a7f9b45fe55 to your computer and use it in GitHub Desktop.
This is for Lina's and Josie's project
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 <ESP8266WiFi.h> | |
#include <WiFiUdp.h> | |
#include <OSCMessage.h> | |
const char* ssid = "PORTABLE_IOT"; | |
const char* pass = "goodlife"; | |
WiFiUDP Udp; // A UDP instance to let us send and receive packets over UDP | |
const unsigned int localPort = 12345; // local port to listen for OSC packets (actually not used for sending) | |
int vibrate = D1; | |
void setup() { | |
Serial.begin(115200); | |
while(!Serial) ; | |
pinMode(LED_BUILTIN, OUTPUT); | |
digitalWrite(LED_BUILTIN, HIGH); | |
// 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(""); | |
digitalWrite(LED_BUILTIN, LOW); | |
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()); | |
pinMode(vibrate, OUTPUT); // set pin for vibration | |
digitalWrite(vibrate,LOW); // start with stopped vibration | |
} | |
void on_slider_1(OSCMessage &msg, int addrOffset) { | |
Serial.println("on (slider 1)"); | |
digitalWrite(vibrate,HIGH); | |
} | |
void on_slider_2(OSCMessage &msg, int addrOffset) { | |
Serial.println("off (slider 2)"); | |
digitalWrite(vibrate,LOW); | |
} | |
void loop() { | |
// RECEIVE | |
OSCMessage in; | |
int size; | |
if( (size = Udp.parsePacket()) > 0) | |
{ | |
while(size--) { | |
in.fill(Udp.read()); | |
} | |
if(!in.hasError()) { | |
in.route("/1", on_slider_1); | |
in.route("/2", on_slider_2); | |
} | |
} // if | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment