Skip to content

Commit fe048ea

Browse files
committed
update sample for Arduino Wifi
update sample for Arduino Wifi to only send notes when connected. This sample is untested (I have no Wifi shield)
1 parent bdbd615 commit fe048ea

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

examples/NoteOnOffEverySecWifi/NoteOnOffEverySecWifi.ino

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ char ssid[] = "yourNetwork"; // your network SSID (name)
1212
char pass[] = "secretPassword"; // your network password (use for WPA, or use as key for WEP)
1313
int keyIndex = 0; // your network key Index number (needed only for WEP)
1414

15-
1615
unsigned long t0 = millis();
16+
bool isConnected = false;
1717

1818
APPLEMIDI_CREATE_INSTANCE(WiFiUDP, AppleMIDI); // see definition in AppleMidi_Defs.h
1919

@@ -86,7 +86,7 @@ void loop()
8686

8787
// send a note every second
8888
// (dont cáll delay(1000) as it will stall the pipeline)
89-
if ((millis() - t0) > 1000)
89+
if (isConnected && (millis() - t0) > 1000)
9090
{
9191
t0 = millis();
9292
// Serial.print(".");
@@ -108,6 +108,7 @@ void loop()
108108
// rtpMIDI session. Device connected
109109
// -----------------------------------------------------------------------------
110110
void OnAppleMidiConnected(char* name) {
111+
isConnected = true;
111112
// Serial.print("Connected to session ");
112113
// Serial.println(name);
113114
}
@@ -116,6 +117,7 @@ void OnAppleMidiConnected(char* name) {
116117
// rtpMIDI session. Device disconnected
117118
// -----------------------------------------------------------------------------
118119
void OnAppleMidiDisconnected() {
120+
isConnected = false;
119121
// Serial.println("Disconnected");
120122
}
121123

@@ -143,4 +145,4 @@ void OnAppleMidiNoteOff(byte channel, byte note, byte velocity) {
143145
Serial.print(" velocity:");
144146
Serial.print(velocity);
145147
Serial.println();
146-
}
148+
}

0 commit comments

Comments
 (0)