Arduino Yun Скачать руководство пользователя страница 19

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 

client.parseInt()

.  

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 

F()

, you'll be printing form the flash memory. This helps 

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); 
 

Содержание Yun

Страница 1: ...ta to the board When programming the Y n you must choose Arduino Y n from the Tools Board menu in the Arduino IDE The Y n is only supported by Arduino IDE 1 5 4 and later Differences from the Arduino...

Страница 2: ...you power your Y n with more than 5V you will likely damage it If you are not powering the Y n from the micro USB connection you can apply power to the Vin and 5V pins on the board It is recommended t...

Страница 3: ...There are several status LEDs on the Y n indicating power WLAN connection WAN connection and USB Additionally pin 13 is connected to one of the status lights Linino...

Страница 4: ...ons or scripts For more on Python visit the Python 2 7 documentation pages If you re getting started with Python for the first time there are a number of excellent resources on line Learn Python the H...

Страница 5: ...by pressing the Wifi reset button for longer longer than 5 seconds but less than 30 the AR9331 processor will reboot The WiFi configuration will be reset and the Y n will start its own wiFi network Ar...

Страница 6: ...This means that if you re using any Serial or Console print println or write statements in setup they won t show up when you open the serial monitor or Console connection To work around this you can c...

Страница 7: ...nloa Once yo comes with ad Arduino u ve read th an installer IDE 1 5 4 i he license a r for the IDE installer or l and if you ag E and driver later and do gree with it rs ouble click click the the ins...

Страница 8: ...By default all available components are selected These include the IDE drivers and shortcuts Select the location you wish to install the IDE...

Страница 9: ...The installer will display its progress as it extracts the files to the proper locations if you chose to install the drivers a pop up window will confirm your selection...

Страница 10: ...ng blocked by a firewall Configuring the onboard WiFi The Y n has the ability to act as an Access Point but it can also connect to an existing network These instructions walk you through connecting yo...

Страница 11: ...will find a page with some diagnostic information about the current network connections The first is your WiFi interface the second is your ethernet connection Press the Configuration button to proce...

Страница 12: ...of 8 or more characters for your Arduino If you leave this field blank the system retains the default password of arduino If you wish you can set the timezone and country It is recommended to set thes...

Страница 13: ...When you press the Configure Restart button the Arduino will reset itself and join the specified network The Arduino network will shut down after a few moments...

Страница 14: ...ation screen Once the program is uploaded the 32U4 processor will restart You should see the LED connected to pin 13 blinking Using the onboard Ethernet When you connect the Yun to a wired network wit...

Страница 15: ...wirelessly It creates a secure connection between the Y n and your computer via SSH Load the following onto your Y n include Console h const int ledPin 13 the pin that the LED is attached to int incom...

Страница 16: ...see the Console by opening a terminal window and typing ssh root yourYunsName local telnet localhost 6571 then pressing enter NB If you are using Windows you must install a terminal emulator PuTTY is...

Страница 17: ...the board through REST calls It demonstrates how you can create your own API when using REST style calls through the browser When running this example make sure your computer is on the same network a...

Страница 18: ...or for parsing and controlling the pins This happens on port 5555 Start the server with server begin server listenOnLocalhost server begin Get Code In loop you ll create an instance of the YunClient f...

Страница 19: ...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 digit...

Страница 20: ...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 re...

Страница 21: ...ode client readStringUntil r if mode input pinMode pin INPUT Send feedback to client client print F Pin D client print pin client print F configured as INPUT return if mode output pinMode pin OUTPUT S...

Страница 22: ...r model and uses WebSockets to communicate between the two It runs a custom webserver on the Y n in python that allows for easy communication There are a number of examples for Spacebrew on the Y n in...

Отзывы: