/* The LCD hookup was included in this script and uses the same hookup as the LCD tutorial (Lesson3) included for the DuinoKit.com project.
Once hooking an analogue component/module to the A0 pin on the Arduino you will be able to view the output for this component in the serial monitor on your computer. This will typically be a number from 1 to 1023.
We will use programming to react to these vale changes from the component.
In this sketch we also used the MAP function in the following line: MapValue=map(analog0,0,1023,1,10); // The Map function
The function above read the A0pin, allows for a rank of 0 to 1023 and then converves these values to 1 to 10. This is the second value being displayed in the serial monitor.
*/
#include <LiquidCrystal.h> //Enable this script for LCD display if desired
// declare variables used in this script int i; int analog0; int MapValue;
// initialize the library with the numbers of the interface pins LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // LCD PinOut (RS, E, D4, D5, D6, D7) void setup() { lcd.begin(16,2); Serial.begin(9600); // initialize the serial communications: }
void loop()
{ analog0=0; for(i=0; i < 20; i++) // Loop and read A0 value 20 times { delay (10); // Slow things down a little for reading values analog0=analog0+analogRead(A0); }
analog0=analog0/i; // Divide total reading sum buy i MapValue=map(analog0,0,1023,1,10); // The Map function