Table of Contents
Introduction
When learning a new programming language, the first code you write typically displays the phrase "Hello World" on the screen. When learning how to use a new board like the TINKERplate, the first example is typically to blink an LED. So, in keeping with tradition, we will blink the small green LED on the front edge of the TINKERplate for our first project.
What You'll Need
- A TINKERplate connected to a programmed Raspberry Pi
- A connection to your Raspberry Pi - either through a monitor and keyboard or remotely with VNC or SSH
Steps
- Bring up a terminal window on your Raspberry Pi:
- Use the Raspberry Pi's built in text editor nano and enter the following code:
- Save your program as LEDblink.py by pressing <CNTL>O and typing in the name. The press <CNTL>X to exit nano.
- Now back at the command line type python3 LEDblink.py and hit <ENTER>
- Now watch the little green LED on your TINKERplate blink 100 times.
- Give yourself a pat on the back for writing your first program.
Here's the code again in case you would prefer to copy and paste it:
1 2 3 4 5 6 7 8 9 10 |
import piplates.TINKERplate as TINK import time for i in range(100): #Repeat this loop 100 times TINK.clrLED(0,0) #LED off time.sleep(0.05) #sleep for 50msec TINK.setLED(0,0) #LED on time.sleep(0.05) #sleep for 50msec print ("I'm all blinked out!") |
The above code can be downloaded from github by typing the following instructions on the command line:
- git clone https://github.com/pi-plates/TINKERplate-Projects.git
- cd TINKERplate-Projects
- python3 LEDblink.py