String key = "D";
key += pin;
Bridge.put(key, String(value));
}
[Get Code]
Set up a function to handle analog calls in the same fashion, except setting the key to A instead
of D when working with the analog input pins :
void analogCommand(YunClient client) {
int pin, value;
pin = client.parseInt();
if (client.read() == '/') {
value = client.parseInt();
analogWrite(pin, value);
// Send feedback to client
client.print(F("Pin D"));
client.print(pin);
client.print(F(" set to analog "));
client.println(value);
String key = "D";
key += pin;
Bridge.put(key, String(value));
}
else {
value = analogRead(pin);
client.print(F("Pin A"));
client.print(pin);
client.print(F(" reads analog "));
client.println(value);
String key = "A";
key += pin;
Bridge.put(key, String(value));
}
}
[Get Code]
Create one more function to handle pin mode changes. Accept the YunClient as the argument,
and create a local variable to hold the pin number. Read the pin value just as you did in the
digital and analog functions.
void modeCommand(YunClient client) {
int pin;
pin = client.parseInt();
[Get Code]