2023-06-26 15:04:13 +02:00
|
|
|
#include <WiFi.h>
|
2023-06-26 15:10:20 +02:00
|
|
|
#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
|
2023-06-20 15:41:52 +02:00
|
|
|
|
2023-06-26 15:04:13 +02:00
|
|
|
// A UDP instance to let us send and receive packets over UDP
|
2023-06-26 15:10:20 +02:00
|
|
|
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;
|
2023-06-20 15:41:52 +02:00
|
|
|
|
2023-06-26 15:10:20 +02:00
|
|
|
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);
|
2023-06-20 15:41:52 +02:00
|
|
|
|
2023-06-26 15:10:20 +02:00
|
|
|
while (WiFi.status() != WL_CONNECTED) {
|
|
|
|
delay(500);
|
|
|
|
Serial.print(".");
|
|
|
|
}
|
|
|
|
Serial.println("");
|
2023-06-20 15:41:52 +02:00
|
|
|
|
2023-06-26 15:10:20 +02:00
|
|
|
Serial.println("WiFi connected");
|
|
|
|
Serial.println("IP address: ");
|
|
|
|
Serial.println(WiFi.localIP());
|
2023-06-20 15:41:52 +02:00
|
|
|
|
2023-06-26 15:10:20 +02:00
|
|
|
Serial.println("Starting UDP");
|
|
|
|
Udp.begin(localPort);
|
|
|
|
Serial.print("Local port: ");
|
|
|
|
Serial.println(localPort);
|
|
|
|
digitalWrite(dirPin, HIGH);
|
|
|
|
}
|
2023-06-20 15:41:52 +02:00
|
|
|
|
2023-06-26 15:10:20 +02:00
|
|
|
void step(OSCMessage &msg) {
|
|
|
|
switch (msg.getInt(0)) {
|
|
|
|
case 0:
|
|
|
|
digitalWrite(stepPin, LOW);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
digitalWrite(stepPin, HIGH);
|
|
|
|
break;
|
2023-06-26 15:04:13 +02:00
|
|
|
}
|
2023-06-20 15:41:52 +02:00
|
|
|
}
|
|
|
|
|
2023-06-26 15:10:20 +02:00
|
|
|
void loop()
|
|
|
|
{
|
|
|
|
OSCMessage msg;
|
|
|
|
int size = Udp.parsePacket();
|
2023-06-20 15:41:52 +02:00
|
|
|
|
2023-06-26 15:10:20 +02:00
|
|
|
if (size > 0) {
|
|
|
|
while (size--) {
|
|
|
|
msg.fill(Udp.read());
|
|
|
|
}
|
|
|
|
//step(msg);
|
|
|
|
step(msg);
|
2023-06-26 15:04:13 +02:00
|
|
|
}
|
|
|
|
}
|