Examples > TFT
This example for the Arduino TFT screen and Esplora draws a white line on the screen, based on the position of the joystick. To clear the screen, shake the Esplora. The values from the accelerometer will determine if the screen should be cleared or not.
Attach the screen to the socket on your Esplora, with the label "SD Card" facing up.
To use the screen you must first include the SPI and TFT libraries. Don't forget to include the Esplora library as well.
Set up the cursor's x & y position. In the example, it starts in the center of the screen; determined by dividing the height and width of the screen by 2.
In setup()
, initialize the display and clear the screen's background.
Read the values of the joystick and map it to a smaller number. It's possible that your joystick doesn't read 0 when it is in the center position. To make sure the cursor only moves when the joystick is intentionally moved, use an if statement to check if it's position is inside a threshold (in this case -10 to 10). If it's within that range, son;t update the cursor position. However, if it is outside of that, move the cursor in the appropriate direction.
You'll want to keep the cursor from moving offscreen with a few if()
statements before you draw the point.
Finally, check the value of the accelerometer. If the value of the x or y axis is over the threshold you determine, clear the screen with background()
.
The complete sketch is below :