TERM 2: ICT NOTES
Chapter 1: Programming With Python
Computer programming is giving a computer instructions (code) on what to do.
An algorithm is a step-by-step analysis of the process while flowcharts explain
the steps of a program in a graphical way.
An algorithm is a step-by-step method to solve a problem.
A flowchart is the graphical representation of an algorithm. In a flowchart, the
steps are in boxes of many kinds and their order is by connecting the boxes with
arrows.
Pseudocode is a precise form of an algorithm without unnecessary steps of
vocabulary and words. It is intended for human reading.
A program is a specific set of ordered operations for a computer to perform.
The program tells the computer what to do.
Hardware describes the electronic and mechanical parts of the computer.
To use hardware, we need software (program).
A computer program is a list of instructions stored as a file on a storage device.
If the program is embedded inside a hardware device, it’s called “firmware.”
Python is a high level programming language.
Python is a scripting language.
Programming languages work with full length code and are capable of running
independently while Scripting languages generally run on small chunks of code
and are embedded into the parent program.
Some famous python websites on the internet include:
Spotify
Pinterest
Google
Python IDLE
File Menu: Basic operations like opening, saving and printing programs
Shell Menu: Reset the environment
Debug Menu: Check your program from any errors
In Python, Indentation is used to indicate a block of code.
A variable is a name given to a storage area that our programs can manipulate.
In a computer’s memory, a variable is a container of memory.
To create and access these containers (variables) we name them to call them in
our program when needed.
A variable can store values in one data type: numeric or string.
Numeric data type: used to hold numeric values like integers, or Float.
String data type: sequence of characters like simple text. Python supports
Unicode characters. Strings are represented by single or double quotes.
In Python, a variable is created the moment we first assign a value to it.
Rules for Python variables:
- Must start with a letter or underscore.
- Cannot start with a number.
- Can contain only alpha-numeric characters and underscores.
- Case sensitive (age, Age and AGE are three different variables)
Python “print” statement is used to output variables.
To combine both text and a variable, Python uses the + character:
x,y= ”Python is”,”awesome”
z=x+y
print(z)
For numbers, the + character works as a math operator.
Comments are a dead piece of code for our references only. They are in-code
documentation. They start with #.
There are three numeric types in Python:
Integer: whole positive or negative numbers without decimals.
Float: positive or negative numbers containing decimals.
Complex: numbers written with “j” as the imaginary part.
To verify the type of any object in Python, use the type() function.
We can convert from one type to another with int() and float() methods.
Python can be used to do any kind of calculation.
A list is an ordered collection of items of any data type.
You can store your data in lists in Python.
You can create a list by putting different comma-separated values between
square brackets.
Each element of a list is assigned a value using an index.
E.g. NewList=[10,20,30,”Samsung”], print(NewList[3]) the output will be
Samsung.
Count in lists start from 0.
Del command is used to delete a list element. del NewList[3]
To add an item to the end of the list, use append()
[Link](“Android”)
Conditional statements is a set of rules performed if a certain condition is met.
IF statement is a programming conditional statement.
If proven true, performs a function or displace information.
A if statement is written using the IF keyword.
ELIF statements means ‘if the previous conditions were not true then try this
condition.’
ELSE statement catches anything not caught by the previous conditions.
A For loop is used for repeating over a sequence.
In Python, a function is a group of related statements that perform a specific
task.
Functions make our code more organized, manageable, avoids repetition and
makes code reusable.
Function names can’t use space. They use ‘_’ instead.
In Python, Keyword def marks the start of the function header.
Function naming follows the same rules of writing identifiers in Python.
A software bug is a coding error that causes an unexpected defect in a computer
program.
There are two types of errors/bug in python or any other programming language.
Syntax Error: errors in typing the commands and variables. Will be automatically
detected and shown in a dialogue box with a suggested solution.
Logical Error: logical mistake while designing the program, occurs due to the
improper planning of the program flow.
The Canvas widget supplies graphics facilities for Tkinter.
For creating rectangles: create_rectangle(coords, options)
For creating a straight line: create_line(coords, options)
For creating ovals: id = C.create_oval(coords, options)
Events execute at a specific actions occurrence.
Tkinter waits for events to happen. It runs most of its time inside an event loop
entered via the mainloop method.
Chapter 2: Robotics
Robotics is a branch of engineering that involves the concept, design,
manufacture, and operation of robots.
Robotics is about the automation of any process.
“A robot is a machine that can behave autonomously.” – Brenton O’ Brien,
Creator of Edison.
Robotics wouldn’t be possible without electronics.
A humanoid or android is a machine with metal arms, legs, bionic eyes and
robotic voice.
Asimov’s Three Laws of Robotics:
1. Robots must never harm human beings.
2. Robots must follow instructions from humans without violating rule 1.
3. Robots must protect themselves without violating rule 1 or 2.
Robots make our lives easier and safer.
Robots perform tasks which humans are not good with safety, speed, consistency,
production and accuracy.
Robotics Industry:
From Sphero Edu app, Sphero is a robotic ball to teach STEM in a fun way.
From Piaggio Group, GITA is a mobile carrier that follows people around and
carries up to 45 pounds.
Moxi robot performs time-consuming logistical tasks in hospital such as setting up
patient rooms. It is imbued with ‘social intelligence.’
Anybots robots serve as remote avatars.
From Boston dynamics, they make robots that have human and animal like agility.
Atlas, a humanoid that uses balance and whole-body skills to achieve two handed
mobile manipulation.
From Harvest, HV-100 is a fully autonomous robot that works alongside people in
unmodified industrial environments (agriculture).
Edison robot has a removable skid and two wheels with a range of built-in
sensors, outputs and motors.
Edison has resistors, capacitors, transistors and motors.
The most important electronic part of Edison is Edison’s Microcontroller (MCU.)
This microcontroller acts as Edison’s brain which
contains programs that allow Edison to make decisions.
Edison can be programmed through four platforms:
- Barcodes and Remote Control
- EdBlock (Graphical Language)
- EdScratch (Scratch Language Interface)
- EdPy (Python Programming Interface)
Function of Edison’s three buttons:
- Record Button: 1 press =
download program, 3
presses = scan barcode
- Stop Button: 1 press =
stop program
- Play Button: 1 press = run
program
Edison’s line tracking sensor is made up of two parts:
a red LED light and a light sensor.
EdPy is Edison’s text based programming application.
The robot is controlled by a program which contains
the instructions and rules governing the robot’s
behavior.
The EdComm cable is used to download programs to Edison.
To connect Edison with your device, you connect EdComm cable in the audio jack.
EdPy app is text-based programming language interface based on Python.
Python gives more flexibility to your program and offers more precise control of
your robot.
1.
P
rogramming Area: where you type python code to control the Edison robot
2. Documentation: where you search the documentation about Python functions
available for use in EdPy, explanations of all available commands including
example code.
3. Recently opened: list of recently opened programs
4. Examples: a list of example programs you can open in programming area
5. Check Code: checks code in programming area for errors, if errors are
detected, a message will appear on the Compiler Output providing details on
errors.
6. Program: downloads program to Edison
7. Compiler Output: when EdPy translates the written code into commands
readable by Edison, this is called “compelling the code.”
8. Line help: translation of python code into English, a guide to use while
programming to show users what each python command does
9. Setup code: all Edison programs must contain the setup code you see every
time you open the EdPy app
The online EdPy programming environment can be used with or without an
account.
Without an account, you can’t save your project online and access your projects
from any browser.
The programming area in EdPy has numbered lines.
All Edison programs must contain the set up code in lines 1 to 11.
When you start a new program, you should start typing on line 13.
You can customize the set up codes parameters per your requirement.
Import Ed is a predefined code to import the library of Edison functions in Python.
Edison has two motors which allow it to move forward, backward and spin left
and right.
To move your Edison robot, you sue the drive function, which has three
parameters: direction, speed and distance.
[Link] set in Setup code controls the measurement of distance.
There are three distance units:
- centimeters: [Link]
- inches: [Link]
- time: [Link]
When you enter code, a code hint menu appears where you can select the entire
code by pressing tab.
Using the code hint menu will help you program in less time with less chance of
syntax errors.
When using the [Link] and [Link] command, the “Distance”
parameter works as the number of steps (cm/inch) Edison has to move. Whereas,
while using Ed.FORWARD_RIGHT, Ed.FORWARD_LEFT, Ed.SPIN_RIGHT,
Ed.SPIN_LEFT, the “Distance” parameter works as the angle at which Edison has
to turn.
A Python variable is a reserved memory location to store values. The variable in a
python program gives data to the computer for processing.
We use variables to represent the data, then when the program is executed the
variables are replaced with real data.
In Python, a for loop is used to repeat sets of commands or statements any
number of times.
For loop allows you to repeat a block of statements as many times as you like.
The range function goes with the for loop often.
In EdPy, range() has one input parameter to define the times of loop should
repeat itself.
While loop repeats statements while a given condition is true.
It tests the condition before executing the loop body.
With [Link](), Edison can play music with its speaker.
The [Link]() has two input parameters: the note and the duration.
The note determines what note to play and the duration determines how long the
note should be played.
IF statement asks whether a condition is true of false.
If true, the program executes statements following the IF statement.
If false, the program ignores the statements inside IF statement and move to the
next line of code outside of the IF statement.
ELIF statement means ‘else if’ in Python. You use ELIF to write a program with
multiple IF conditions.
Edison has two obstacle detection beams, one on front left, other on front right.
Edison’s sound sensor can respond to any loud sounds detected.
Edison’s light tracking sensor is made up of a red LED and a light sensor.
Chapter 3: Mobile App Development
AppLab is an application
to build new apps and
share them.
On the left side is your
app.
The right side is the code
that will make it run.
You can drag blocks from
the tool box to build your
program.
The setProperty() block changes the look of the elements on your screen. Like the
buttons, labels and your screen.
Elements have a lot of properties like their text and background colour, or font
size.
Events are user actions. To do this in AppLab, you use the block onEvent()
The playSound() block allows you to add sound to your app. You can either
upload a sound from your sound file from your computer or search for a sound on
Sound Library.
To add images to your elements, you can use the setProperty() block. You can
upload an image from your computer, insert link to an image or look for an image
on Icon Library.