Getting Started with TinyScreen Programming
Let’s look at some of the basics of O Watch programming using TinyScreen.
When you display any item on the screen you need to tell the O Watch where to print it. e.g. if you draw something on the screen like a rectangle, you need to specifiy the starting position or the x,y co-ordinates. Note that the starting point is the left top and the first pixel starts at (0,0) meaning (95,63) is the right-bottom corner the highest values for x & y respectively.
Let’s refer to the Hello World example again.
* Hello World
* This is a simple program that blinks 'Hello World'
* This for the Arduino compatible TinyScreen+ by http://tiny-circuits.com
* This example is in the public domain.
* Published 29 Feb 2016
* by O Watch http://theowatch.com
#include <TinyScreen.h> //Include TinyScreen library
TinyScreen display = TinyScreen(TinyScreenPlus); //Set TinyScreen board type
int delaytime = 1000; //Declaring a variable to set the delay between text blink
// The setup function runs once when you power on the board
display.begin(); //Initializes TinyScreen board
display.setFlip(1); //Flips the TinyScreen rightside up for O Watch
display.on(); //Turns TinyScreen display on
display.setFont(liberationSansNarrow_12ptFontInfo); //Set the fornt type
display.fontColor(TS_8b_Blue,TS_8b_Black); //Set the font color, font background
display.setBrightness(10); //Set display brightness 0 - 15
// the loop function runs over and over again forever
display.setCursor(15,25); //set the cursor to x, y position, where to start next print/draw instruction
display.print("Hello World!"); //print command
delay(delaytime); //delay for 1000 milliseconds or one second
display.clearScreen(); //clears the screen blank
delay(delaytime); //delay again for one second
Here you see a number of commands start with the prefix
display. All the commands that start with
display. prefix are TinyScreen functions included in the TinyScreen library.
Following are the TinyScreen functions used in this example:
display.begin()– This initializes the TinyScreen board. It is required at the start of all O Watch programs.
display.setFlip(1)– Flips the display right-side up. By default TinyScreen prints everything upside down from O Watch perspective. So we need this for all O Watch programs as well. If you wish to flip the display back then you can set this to 0 or remove this.
display.on()– This switches on the display. You can use
display.off()to switch off the display and save power. This can be in the setup or it could be in the loop as well if you wish to switch the screen on and off based on certain events.
display.setFont(liberationSansNarrow_12ptFontInfo)– sets the font type in which text will be printed on screen. You can change this to other available fonts.
display.fontColor(TS_8b_Blue,TS_8b_Black)– Sets the color and background for text printed on screen.
display.setBrightness(10)– Sets the display brightness (and the amount of power used). Values are from 0-15.
display.setCursor(15,25)– Sets the x,y position on the screen where the next print comman will begin.
display.print("Hello World!")– This is the TinyScreen print command.
display.clearScreen()– Clears the whole screen.
- Change the code so that the text is on for 100 milliseconds and off for 1000.
- Change the code so that the text turns on when the sketch starts and stays on.
- Change the code to display text 5 times in different positions before clearing screen