Last active
December 9, 2024 16:05
-
-
Save lislis/b9943fa195f3544b73999693a7e89d53 to your computer and use it in GitHub Desktop.
esp32 osc for Max
This file contains hidden or 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 <WiFi.h> | |
#include <WiFiUdp.h> | |
#include <OSCMessage.h> | |
#define WIFI_SSID "xxxxxxxxxxx" | |
#define WIFI_PASS "1234" | |
IPAddress outIp(192, 168, 0, 43); | |
const unsigned int outPort = 9999; | |
WiFiUDP Udp; | |
const int photoPin = 2; | |
const int potiPin = 15; | |
void setup() { | |
Serial.begin(115200); | |
pinMode(photoPin, INPUT); | |
pinMode(potiPin, INPUT); | |
Serial.println(); | |
Serial.println(); | |
Serial.print("Connecting to "); | |
Serial.println(WIFI_SSID); | |
WiFi.begin(WIFI_SSID, WIFI_PASS); | |
while (WiFi.status() != WL_CONNECTED) { | |
delay(500); | |
Serial.print("."); | |
} | |
Serial.println(""); | |
Serial.println("WiFi connected."); | |
Serial.println("IP address: "); | |
Serial.println(WiFi.localIP()); | |
Udp.begin(8888); | |
} | |
void loop() { | |
int photo_read = analogRead(photoPin); | |
Serial.print(photo_read); | |
Serial.print(","); | |
char* address = "/photo"; | |
OSCMessage msg(address); | |
msg.add((unsigned int)photo_read); | |
Udp.beginPacket(outIp, outPort); | |
msg.send(Udp); | |
Udp.endPacket(); | |
msg.empty(); | |
int poti_read = analogRead(potiPin); | |
Serial.print(poti_read); | |
address = "/poti"; | |
msg.setAddress(address); | |
msg.add((unsigned int)poti_read); | |
Udp.beginPacket(outIp, outPort); | |
msg.send(Udp); | |
Udp.endPacket(); | |
msg.empty(); | |
Serial.println(""); | |
delay(10); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment