I've got this code to fire an OSC message when a button is pressed & depressed.
It works fine on my Arduino Uno.
However, it doesn't work when uploaded to my Arduino Nano with an ethernet shield.
I cant ping it & it doesn't respond to button presses.
#include <OSCMessage.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <SPI.h>const int button1 = 3; // the number of the pushbutton pin
long on=0;
long off=0;
int buttonState1 = 0; // variable for reading the pushbutton1 statusEthernetUDP Udp;
//the Arduino's IP
IPAddress ip(10, 10, 10, 20);
//destination IP
IPAddress outIp(10, 10, 10, 30);
//port
const unsigned int outPort = 8000;byte mac[] = {
0x82, 0x40, 0x56, 0xF9, 0xD1, 0x21 };void setup() {
pinMode(button1, INPUT_PULLUP); // PULLUP add 5v to pin without hardware prevent pin from floating between HIGH and LOW
Ethernet.begin(mac,ip);
Udp.begin(8888);}
void loop() {
// read the state of the pushbutton value:
buttonState1 = digitalRead(button1);
// check if the pushbutton is pressed.
// if it is, the buttonState is LOW:if (digitalRead(button1)==LOW){
if (on == 1) {OSCMessage msg("/string/1/send");
Udp.beginPacket(outIp, outPort);
msg.send(Udp); // send the bytes to the SLIP stream
Udp.endPacket(); // mark the end of the OSC Packetmsg.empty(); // free space occupied by message
}
on++;}
if (digitalRead(button1)==HIGH){
if (off == 1) {OSCMessage msg("/string/2/send");
Udp.beginPacket(outIp, outPort);
msg.send(Udp); // send the bytes to the SLIP stream
Udp.endPacket(); // mark the end of the OSC Packetmsg.empty(); // free space occupied by message
}
off++;}
if (buttonState1 == HIGH) {
delay(20);
on=0;
}
if (buttonState1 == LOW) {
delay(20);
off=0;
}
}
Any help is very much appreciated!