Lesson 2: Displaying Raw Analog Input Information

 

Written by Jonathan Sim

You can find this lesson and more in the Arduino IDE (File -> Examples -> Andee). If you are unable to find them, you will need to install the Andee Library for Arduino IDE.

Works on iOS and Android
In this lesson, I'll show you how you can easily display analog sensor data from the sensors that are connected to the Annikken Andee x Arduino.

Here's a look at what the code below will create:

Lesson02.png

Contents

Top of the Code

Works with any sensor. You can use the Light Dependent Resistor to try this out!

Always include these libraries. Annikken Andee needs them to work with the Arduino!

#include <SPI.h>
#include <Andee.h>

// We'll creating one object to display the analog input signal
AndeeHelper analogDisplay;

// We'll use Analog Input Pin A0 to read our analog input.
// Change the pin number if you are using another pin.
const int analogInputPin = A0;


setup()

The setup() function is meant to tell Arduino what to do only when it starts up.

void setup()
{
  Andee.begin();  // Setup communication between Annikken Andee and Arduino
  Andee.clear();  // Clear the screen of any previous displays
  setInitialData(); // Define object types and their appearance
}

setInitialData()

This is the function meant to define the types and the appearance of all the objects on your smartphone

void setInitialData()
{
  // Only one display box this time
  analogDisplay.setId(0);  // Each object must have a unique ID number
  analogDisplay.setType(DATA_OUT);  // This defines your object as a display box
  analogDisplay.setLocation(0, 0, FULL); // Sets the location and size of your object
  analogDisplay.setTitle("Analog Reading");
  analogDisplay.setData(""); // We'll update it with new analog data later.
}

loop()

Arduino will run instructions here repeatedly until you power it off.

void loop()
{
  // Read value from analog pin and store it in an int variable
  int reading = analogRead(analogInputPin); 
  analogDisplay.setData(reading); // Set the display box with new data value
  analogDisplay.update(); // Update the display to show the new value
  
  // A short delay is necessary to give Andee time to communicate with the smartphone
  delay(500); 
}

Visual Graph View

Did you know that if you press and hold on the display box, your phone will draw a graph?

This is what you'll see:

Visualgraph.png
comments powered by Disqus