Mission 9 - Understanding Data
 DuinoKit Essentials   Started by Daniel Alich   2017-06-27 21:37:23 -04:00   Comments: 1    Viewed: 49

  1. Daniel Alich
    Daniel Alich Member Staff Member


    /*
    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

    Serial.print(analog0);
    Serial.print("t");
    Serial.println(MapValue);

    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print(analog0);
    lcd.setCursor(5, 0);
    lcd.print(MapValue);

    delay(10);
    }
    Daniel Alich, 2017-06-27 21:37:23 -04:00
  2. (You must log in or sign up to post here)

Report Post

Write your reason

Log in | Sign up
Terms & Conditions!
Help!