Lesson 26: Create Date Input Button

 

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
You can create date input buttons to receive user date inputs. This will come in very handy especially when you want to schedule tasks at a particular date.

Lesson26.png


Contents

Top of the Code

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

// We'll need a date input button and a display box to provide feedback
AndeeHelper displaybox;
AndeeHelper dateInputButton;

int dd, mm, yyyy; // Variables to store user date input
char tempString[20]; // Used to store date as a string

setup()

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()

void setInitialData()
{
  displaybox.setId(0);
  displaybox.setType(DATA_OUT);
  displaybox.setLocation(0,0,FULL);
  displaybox.setTitle("Your Selected Date");
  displaybox.setData("No Date Selected");
  
  dateInputButton.setId(1);
  dateInputButton.setType(DATE_IN); // Sets object as a date input button
  dateInputButton.setLocation(1,0,FULL);
  dateInputButton.setTitle("Select Date");
  
  // Optional Setting. When the user opens up the date picker, Andee will display this
  // date as the initial date to choose.
  dateInputButton.setDefaultDate(25, DEC, 2013); // Format: day, month, year
}

loop()

void loop()
{
  if( dateInputButton.isPressed() )
  { 
    dateInputButton.ack();
    
    // Display date picker and store it in the three variables - dd, mm, and yyyy
    dateInputButton.getDateInput(&dd, &mm, &yyyy); 
    
    // String the three variables into a single date string
    sprintf(tempString, "%02d/%02d/%02d", dd, mm, yyyy);
    displaybox.setData(tempString);
  }
  
  displaybox.update();
  dateInputButton.update();
  
  delay(500); // Always leave a short delay for Bluetooth communication
}
comments powered by Disqus