Quick Reference Tables Chapter 1 Raspberry Pi Startup Command Quick Reference Table Command Description sudo Gives the user root or super user permissions. sudo halt Shuts down (halts) the power to the Raspberry Pi. sudo reboot Shuts down the power to the Raspberry Pi and then restarts it. Achievement Unlocked: Your Raspberry Pi is up and running! BC1 Bonus chapter.indd 1 Trim size: 7.375 in × 9.
Chapter 2 Command Line Quick Reference Table BC2 Bonus chapter.indd 2 Command Description cat Displays the contents (catalog) of the text file. cd Changes directory. For example, the command cd Desktop moves you into the Desktop directory. cd .. Moves you up the directory tree to the parent directory. cp Makes another copy of a file. clear Allows you to clear the terminal. date Displays the time and date. ls Displays a list of files and folders in the current directory.
Achievement Unlocked: Your Raspberry Pi responds to your commands! BONUS CHAPTER 1 Bonus chapter.indd 3 Trim size: 7.375 in × 9.
Chapter 3 Scratch Command Quick Reference Table Command Description Control Blocks broadcast x Sends a message to all the sprites and the stage which can be used to synchronize scripts across multiple sprites and the stage. forever Repeatedly iterates actions within set. forever if Checks whether a condition is true, over and over. If the condition is true the program runs the blocks inside. if...else If the condition is true, the program runs the blocks inside the if section.
Command Description Looks Blocks change size by x Changes sprite’s size by x amount. hide Hides a sprite from the stage. next costume Changes sprite’s costume to the next costume in the list. Command Description say xxx Shows sprite’s speech bubble saying xxx. set size to x Sets a sprite’s size to x percent of its original size. show Makes a sprite appear on the stage. switch to background x Changes the background of the stage. switch to costume x Changes the costume of a sprite.
Chapter 4 Turtle Graphics Command Quick Reference Table See also the Scratch Quick Reference Table in Adventure 3 Commands Description Pen Blocks (Scratch) change pen color by x Changes pen’s colour by x amount. change pen shade by x Changes the pen’s shade by x amount. clear Clears all pen marks and stamps from the stage. pen down Puts down a sprite’s pen so that it will draw. pen up Lifts a sprite’s pen so it does not draw. set pen color to x Sets a pen’s colour to your choice.
Commands Description Additional Commands for loops are traditionally used when you have a piece of code that you want to repeat x number of times. Example: for for i in [0,1,2,3,4,] for i in range(): A for loop using the range() function that creates a list containing numbers. range() The range() function generates a list of numbers in progression. Achievement Unlocked: You can create Turtle Graphics on your Raspberry Pi! BONUS CHAPTER 1 Bonus chapter.indd 7 Trim size: 7.375 in × 9.
Chapter 5 Python Command Quick Reference Table Command Description # The # symbol is used at the beginning of a code line to indicate the line is a comment, not part of the program’s instructions to the computer. \n Returns a new line in a string. break Breaks out of a for or while loop. def Allows you to define a function of your creation. elif Short for ‘else if’, the elif syntax allows you to create multiple conditions that make something happen when they return a value of true.
Achievement Unlocked: You can program in Python on your Raspberry Pi! BONUS CHAPTER 1 Bonus chapter.indd 9 Trim size: 7.375 in × 9.
Chapter 6 Minecraft Pi Command Quick Reference Table Command Description from mcpi.minecraft import minecraft Imports the Minecraft modules. mc = minecraft.create() Connects to Minecraft Pi by creating the Minecraft object. pos = mc.player.getPos() Returns the players position with floats. pos = mc.player.getTilePos() Returns the players position with integers. postToChat(msg) Posts a message to chat in Minecraft Pi. setBlock Sets a block at coordinates.
Chapter 7 Sonic Pi Command Quick Reference Table Command Description live_loop :name do...end Runs any code between do and end at the same time as another live_loop block. play x Plays note x. play_pattern [60,60,67,67,69,69,67] Plays a pattern of notes inside a list. rand Returns a random number. .reverse An algorithm that reverses the order of notes in a list. .shuffle An algorithm that shuffles the order of notes in a list. use_synth :fm Sets the synth sound; in this example, the fm sound.
Chapter 8 GPIO Pins Command Quick Reference Table Command Description from gpiozero import LED, Button Imports the Raspberry Pi gpiozero module Led = LED(2) Creates an LED against a pin number as well as identifying it as an output led.on() Sets output GPIO to true or on led.off() Sets output GPIO to false or off if button.is_pressed: Sets a condition for a button press if pir.
Chapter 9 Accessories Command Quick Reference Table Command Description From picamera import PiCamera Imports the picamera modules camera.start_preview() Starts the camera preview camera.stop_preview() Stops the camera preview camera.capture(‘/home/pi/Pictures/ image.jpg’) Captures a jpeg image and stores it in the Pictures directory avconv –r 10 –i image%02d.jpg – qscale 2 timelapse.
Chapter 10 Achievement Unlocked: Your big Raspberry Pi project! BC14 Bonus chapter.indd 14 ADVEN T URES IN RASPBERRY PI Trim size: 7.375 in × 9.