Want to make interactive content? It’s easy in Genially!

Over 30 million people build interactive content in Genially.

Check out what others have designed:

Transcript

MRS. MCLEMORE

LEGO EDUCATIONIMPORTING LIBRARIES

HS ROBOTICS

STUDENTS WILL BE ABLE TO:

  • Learn why a Python program must have libraries imported.
  • Import libraries.
  • Run a program.

MRS. MCLEMORE

LESSON OBJECTIVES

How can engineers and computer programmers work together to create a way to communicate ideas to others?

MRS. MCLEMORE

ESSENTIAL QUESTION

When writing a Python program, you will need to make sure you “gather” all the things you will use before you start to make a model run.

MRS. MCLEMORE

BEFORE WE START

the rules for writing statements (lines of code)

MRS. MCLEMORE

PYTHON SYNTAX

In Python, each statement begins with a level of indentation and ends with a line break. Indentation is the number of spaces before a statement.Lines with the same number of spaces have the same indentation level and belong to the same code block. The SPIKE App uses 4 spaces for each indentation level.

MRS. MCLEMORE

PYTHON SYNTAX

Syntax highlighting in the Code Editor shows comments, keywords, text, and numbers in different colors so the code is easier to read.# This is a comment.print('LEGO')if True: print(123)

MRS. MCLEMORE

PYTHON SYNTAX

“The imported libraries are located at the beginning of the .py file and should appear only once in the program.”The .py file is the Python program that is being coded. “.py” stands for Python.You do not see .py anywhere on the canvas because the .py file contains everything on the canvas.

MRS. MCLEMORE

PYTHON FILE

When using Python to program, students must import the libraries, the words, or terms, that signal the program to recognize the hardware that can be used.

MRS. MCLEMORE

WHAT IS A LIBRARY?

Because Python is a text-based coding language, capitalization and punctuation are important. For the SPIKE App to communicate with the SPIKE Prime components, you will need the right libraries that link the hardware components to the software.

MRS. MCLEMORE

HELPFUL TIPS

Open your SPIKE Prime sets and locate all the hardware pieces. Pull each hardware item out of the set and lay them on the table. (1 Hub, 3 motors, 3 sensors)

MRS. MCLEMORE

LETS GET STARTED pt. 1

IMPORT SOFTWARE
IMPORT HARDWARE

from hub import light_matriximport runloopasync def main(): # write your code here await light_matrix.write("Hi!")runloop.run(main())

MRS. MCLEMORE

LETS GET STARTED pt. 2

  • light_matrix is the 5x5 grid on the hub
  • Button refers to the three buttons located at the bottom on the front of the hub - left, center and right buttons
  • light is the light color surrounding the center button
  • force_sensor refers to the force sensor which contains a black button to push in
  • motion_sensor is contained within the hub, like a gyro

MRS. MCLEMORE

HARDWARE TERMS pt.1

  • speaker is on the outside of the hub
  • color_sensor is the small square color sensor that has one light
  • App is the ability to play sounds
  • distance_sensor is the rectangular ultrasonic sensor that appears to have two “eyes”
  • motor refers to any size motor
  • motor_pair refers to two motors that will work in tandem.

MRS. MCLEMORE

HARDWARE TERMS pt. 2

Open your SPIKE Prime app on your Chromebook.Select "New Project" and click Python

MRS. MCLEMORE

LETS GET STARTED pt. 2

Connect your HUB to your Chromebook

MRS. MCLEMORE

LETS GET STARTED pt. 3

Run the sample code by selecting the play button (yellow circle with white triangle) at the bottom of the screen. The light matrix should scroll Hi! Across the display.

MRS. MCLEMORE

RUN THE CODE

Locate the Knowledge Base on the right-side panel.Select API Modules to view the different libraries and how to import them using code

MRS. MCLEMORE

HOW TO IMPORT LIBRARIES

Change the hardware, keywords, or text and re-run your program to see the differences.

MRS. MCLEMORE

TIME TO EXPLORE

  • Students are responsible for materials management.
  • Parts should not be shared between sets.
  • If a part is missing, ask the teacher.
  • Remember, the teacher has limited spare parts.

MRS. MCLEMORE

REMINDERS!

  • Rate your team on a scale of 1-3, on their time management today.
  • Rate your team on a scale of 1-3, on their materials (parts) management today.

MRS. MCLEMORE

EXIT TICKET