tailieunhanh - Practical Arduino Cool Projects for Open Source Hardware- P26
Practical Arduino Cool Projects for Open Source Hardware- P26: A schematic or circuit diagram is a diagram that describes the interconnections in an electrical or electronic device. In the projects presented in Practical Arduino, we’ve taken the approach of providing both a photograph and/or line drawing of the completed device along with a schematic. While learning to read schematics takes a modest investment of your time, it will prove useful time and time again as you develop your projects. With that in mind, we present a quick how-to in this section | CHAPTER 12 WATER TANK DEPTH SENSOR see in a moment that wouldn t actually work. Finally the TANK_SENSOR define is to specify which analog input the sensor is connected to. The shield design in this project uses analog input 0. int sensorValue 0 int tankLevel 0 define TANK_SENSOR 0 The tank-level sensor won t provide a value that varies all the way from 0V when empty to 5V when full so we need some calibration values that are used later in the program to adjust the lower and upper levels of the read range. These will need to be altered to suit your specific installation using a procedure that will be explained in a moment. define TANK_EMPTY 0 define TANK_FULL 1023 The setup function is simple but the function is worth taking a look at. It accepts an argument that specifies the callback function to be executed in response to a connection request and in this case we ve told it to use the function sendWebPage . This is a bit like setting up an interrupt because the sendWebPage function is never called directly in the program but by defining it and passing it to it will be invoked automatically at the appropriate time. void setup sendWebPage Next the sketch opens a serial connection to the host so it can send status messages back to you and enables verbose mode so the server will send log messages via that connection. 38400 true The main program loop is trivial. All it does is repeatedly call the method so that incoming data queued by the WiShield will be processed. Without this a connection request from your browser will arrive at the WiShield and sit in the buffer without ever being acted on. void loop delay 10 The last function generates the web page to send back to the browser. It s just a slightly extended version of the example included with the WiShield library with the addition of the reading from the tankdepth sensor connected to analog .
đang nạp các trang xem trước