Lesson 32: Enforce Screen Settings

 

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 Android
In this lesson, I'll show you how to make sure that the screen stays always on, and how to enforce the screen orientation.

Contents

Top of the Code

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

// We'll just create a display box
AndeeHelper displaybox;

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
  
  // If you want your screen to remain on at all times, call this function:
  Andee.screenAlwaysOn(true);
  // This will prevent your phone from sleeping.
  // You can call Andee.screenAlwaysOn() anytime in your code.
  // To allow your phone to go back to sleep, call: Andee.screenAlwaysOn(false);
}

setInitialData()

void setInitialData()
{
  // Let's draw the button!
  displaybox.setId(0); // Don't forget to assign a unique ID number
  displaybox.setType(DATA_OUT); // Defines object as a display box
  displaybox.setLocation(0,0,FULL);
  displaybox.setTitle("Current Orientation Mode");
  displaybox.setUnit("Screen orientation will change every 5 seconds");
}

loop()

void loop()
{
  // This loop will demonstrate the various screen orientation modes
  // that you can enforce.
  // You can call these commands within the setup() function. I have
  // placed them here just to demonstrate the various screen
  // orientation modes that you can enforce.
  for(int i = 0; i < 5; i++)
  {
    if(i == 0)
    {
      // Enforce auto-orientation
      Andee.setScreenOrientation(AUTO);
      displaybox.setData("AUTO");
    }
    if(i == 1)
    {
      // Enforce portrait orientation
      Andee.setScreenOrientation(PORTRAIT);
      displaybox.setData("PORTRAIT");
    }
    if(i == 2)
    {
      // Enforce landscape orientation
      Andee.setScreenOrientation(LANDSCAPE);
      displaybox.setData("LANDSCAPE");
    }
    if(i == 3)
    {
      // Enforce upside down portrait orientation
      Andee.setScreenOrientation(PORTRAIT_REVERSE);
      displaybox.setData("PORTRAIT_REVERSE");
    }
    if(i == 4)
    {
      // Enforce upside down landscape orientation
      Andee.setScreenOrientation(LANDSCAPE_REVERSE);
      displaybox.setData("LANDSCAPE_REVERSE");
    }
    displaybox.update();
    delay(5000); // Always leave a short delay for Bluetooth communication
  }
}
comments powered by Disqus