As I have chosen the UDP path to control the thingy, I needed a way to send the command datagrams to it. The UDP receive example I used for the arduino, included a processing example for UDP send. After messing around a little bit with processing, I got this:
import hypermedia.net.*; UDP udp; // define the UDP object boolean overDoorButton = false; PFont f; void setup() { udp = new UDP( this, 31337 ); // create a new datagram connection on port 31337 udp.listen( true ); // and wait for incoming message size(220,190); f=createFont("Arial",16,true); } void draw() { background(10,250,50); textFont(f,16); fill(0); if (overDoorButton == true) { fill(200,100); }else { noFill(); } rect(35, 60, 150, 75); text("ABRIR",85,100); } void mousePressed() { String ip = "xx.xx.xx.250"; // the remote IP address int port = 1337; // the destination port if(overDoorButton){ udp.send("OPEND0123", ip, port ); // the message to send } } void mouseMoved() { checkButtons(); } void mouseDragged() { checkButtons(); } void checkButtons() { if (mouseX > 35 && mouseX < 185 && mouseY > 60 && mouseY < 135) { overDoorButton = true; } else { overDoorButton =false; } } void receive( byte[] data ) { // <-- default handler //void receive( byte[] data, String ip, int port ) { // <-- extended handler for(int i=0; i < data.length; i++) print(char(data[i])); println(); }The graphic result is something like this:
To unlock the door, just press the button, and presto! One less excuse to get up and walk.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.