tailieunhanh - Practical Arduino Cool Projects for Open Source Hardware- P21

Practical Arduino Cool Projects for Open Source Hardware- P21 | CHAPTER 10 WATER FLOW GUAGE unsigned long oldTime The setup routine is fairly straightforward except for the definition of the interrupt handler which we ll get to in a moment. First it makes some calls to methods in the lcd object. The begin call specifies the number of columns and rows in the attached LCD then the cursor is set to character 0 on row 0 the top row before 16 spaces are printed. The cursor is then set to character 0 on row 1 the second row and another 16 spaces printed. This ensures that the LCD starts off blank with no leftover characters visible on the display. Normally it s not a problem but this just ensures that anything left from a previous program you may have run such as an LCD test program is erased. void setup 16 2 0 0 0 1 A serial connection is then opened to the host to report values back. 38400 The pin to control the status LED is switched to an output and then set HIGH which turns off the LED since we connected it via a dropper resistor to 5V. pinMode statusLed OUTPUT digitalWrite statusLed HIGH The I O lines connected to the counter reset buttons are set as inputs so we can read the button state but then the program writes to them as if they re outputs. This has the effect of activating the ATMega CPU s internal 20K pull-up resistors on those inputs biasing them high unless they are pulled low via the button and the 1K resistors. pinMode resetButtonA INPUT digitalWrite resetButtonA HIGH pinMode resetButtonB INPUT digitalWrite resetButtonB HIGH The pin for connecting the Hall-effect sensor is then treated in the same way. We set it to be an input then write a HIGH value to it activating the internal pull-up resistor so that it will be high unless the open-collector output of the sensor pulls it low. pinMode sensorPin INPUT digitalWrite sensorPin HIGH A number of variables are initialised to starting values. pulseCount 0 flowMilliLitres 0 totalMilliLitresA 0 .