Download Print this page

Arduino Yún Manual page 19

Advertisement

void process(YunClient client) {
String command = client.readStringUntil('/');
if (command == "digital") {
digitalCommand(client);
}
if (command == "analog") {
analogCommand(client);
}
if (command == "mode") {
modeCommand(client);
}
}
[Get Code]
Create a function to deal with digital commands. Accept the client as the argument. Create some
local variables to hold the pin and value of the command.
void digitalCommand(YunClient client) {
int pin, value;
[Get Code]
Parse the client's request for the pin to work with using
If the character after the pin is a "/", it means the URL is going to have a value of 1 or 0
following. This value will assign a value to the pin, turning it HIGH or LOW. If there is no
trailing "/", read the value from the specified pin.
pin = client.parseInt();
if (client.read() == '/') {
value = client.parseInt();
digitalWrite(pin, value);
}
else {
value = digitalRead(pin);
}
[Get Code]
Print the value to the client and update the datastore key with the current pin value.
By wrapping the value to the client in
conserve space in SRAM, which is useful when dealing with long strings like URLs.
The key will be the pin, and type. For example D2 will be saved for for digital pin 2. The value
will be whatever value the pin is currently set to, or was read from the pin.
client.print(F("Pin D"));
client.print(pin);
client.print(F(" set to "));
client.println(value);
client.parseInt()
, you'll be printing form the flash memory. This helps
F()
.

Advertisement

loading
Need help?

Need help?

Do you have a question about the Yún and is the answer not in the manual?

Questions and answers

Subscribe to Our Youtube Channel