Paste your first Python program in the Raspberry Pro Preview

Now it is time to import a complex program and to learn from it.

To access the full video please subscribe to FLLCasts.com

Subscribe

  • #831
  • 09 Apr 2018

TL:DR.

Copy the contents of the material ledPulseDemo.py;

type

nano ledPulseDemo.py;

right click to paste;

press Ctrl+O, then Enter, then Ctrl+X;

type

python ledPulseDemo.py

and follow the on-screen instruction.

 

Create the demonstration program

The program ledPulseDemo.py could be already in the folder Perfect_Programs, but could be also missing. Do you remember how to ask the command line for long list of files and directories in a folder?
We will assume the program is not already there and we will create it together. 

Open the ledPulseDemo.py from the material here and select all the text. Then copy it.

 

Nano text editor

The simplest text editor in a command line interface that we know is called Nano (as in nano-technology, a small thing).

With the command nano you can open files and read and write in them.

Type

nano ledPulseDemo.py

and this command will open an editor for the file ledPulseDemo.py. If the file is already there, you will see its contents (use TAB or even double TAB while typing to check if something exists). If the file does not exist, the editor will be blank, empty and you can create the file.

Now that you have a blank nano editor opened, do a simple right mouse click (on Windows) and that will paste your earlier copy into the nano editor.

To save your creation in nano you must press Control key and O (as in output). A question about the filename appears in the bottom of the screen. It asks about the filename and the name ledPulseDemo.py is already filled, and the choise Yes is highlighted. 
So simply press Enter.

Now in order to close the editor press Control key and X (as in Exit).

 

Start the program

You are smart people, figure out on your own how to ask python to start the program that we just created.

 

Open the program and read each and every line of it

Now open nano once again and this time read all the program and figure out what acomplishes each line of code. After that it is going to be your turn to create code.

Python demo program to blink and pulse LED

Part of the Perfect STEM course, you should have a Raspberry Pi and an LED connected on GPIO 18 for this example to work.

Courses and lessons with this Tutorial

This Tutorial is used in the following courses and lessons

Image for Perfect STEM course. Module 1 - Smart Car with Raspberry PI
  • 118
  • 42:47
  • 136