66 lines
1.3 KiB
C++
66 lines
1.3 KiB
C++
#include <WiFi.h>
|
|
#include <WiFiUdp.h>
|
|
#include <OSCMessage.h>
|
|
#include <OSCBundle.h>
|
|
#include <OSCData.h>
|
|
char ssid[] = "cohabit"; // your network SSID (name)
|
|
char pass[] = "lewifidecohabit"; // your network password
|
|
|
|
// A UDP instance to let us send and receive packets over UDP
|
|
WiFiUDP Udp;
|
|
const unsigned int localPort = 16403; // local port to listen for UDP packets (here's where we send the packets)
|
|
int stepPin = 14;
|
|
int dirPin = 12;
|
|
|
|
void setup()
|
|
{
|
|
Serial.begin(115200);
|
|
// initialize LED digital pin as an output.
|
|
pinMode(stepPin, OUTPUT);
|
|
pinMode(dirPin, OUTPUT);
|
|
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(localPort);
|
|
digitalWrite(dirPin, HIGH);
|
|
}
|
|
|
|
void step(OSCMessage &msg) {
|
|
switch (msg.getInt(0)) {
|
|
case 0:
|
|
digitalWrite(stepPin, LOW);
|
|
break;
|
|
case 1:
|
|
digitalWrite(stepPin, HIGH);
|
|
break;
|
|
}
|
|
}
|
|
|
|
void loop()
|
|
{
|
|
OSCMessage msg;
|
|
int size = Udp.parsePacket();
|
|
|
|
if (size > 0) {
|
|
while (size--) {
|
|
msg.fill(Udp.read());
|
|
}
|
|
//step(msg);
|
|
step(msg);
|
|
}
|
|
} |