Now that the keyboard is connected, let's figure out how to accept commands on Raspberry Pi. Now that you can enter commands wirelessly, the next step is to create a program that can take these commands and then have your project execute them. There are a couple of options here; you'll see examples of both. The first is to simply include the command interface in your program. Let's take an example of the program you wrote to move your wheeled robot, dcmotor.py
. If you want, you can copy that program using cp dcmotor.py remote.py
.
In order to add user control, you need two new programming constructs, the while
loop and the if
statement. Let's add them to the program and then we will learn what they do. The following is a listing of the area of code you are going to change:
You will edit your program by making some changes. Add the code in the preceding screenshot just below the ser = serial.Serial('/dev/ttyUBS0', 19200, timeout = 1)
statement. The...