Coding Example 1: Hello World!

Download Report

Transcript Coding Example 1: Hello World!

Coding
By: Katie XXXXXX
Agenda
Programming Languages
Hardware
Coding Example 1: Hello World
Coding Example 2: Fibonacci Sequence
Coding Example 3: Balloon POP!
More Examples
Resources
Programming Languages
SCRATCH: A beginners language designed to make programming fun for small kids.
PYTHON: A powerful, easy to learn, and widely used programming language.
JAVA: A very popular programming language especially for web-based applications.
C/C++/C#: A set of low level programming languages.
Very powerful, extremely widely used, hard to learn.
Dozens, if not hundreds, of more obscure programming languages.
Programming Language Selection
For elementary school aged kids, SCRATCH is probably the best choice.
PYTHON is generally considered the best learning language.
It's powerful, quick to learn,
and makes it easier to learn the other languages like JAVA and C later.
Hardware
IPAD: iPads are made to be simple to use making it hard to program on them.
PC/Laptops: Powerful platforms for coding. Expensive. Hard to interface with electronics.
Raspberry Pi: A computing platform designed to get kids interested in programming,
and to be about the cost of a school textbook.
Hardware: Raspberry PI
The Raspberry Pi is a credit card sized computer, costing between $25
and $35 (depending on version).
It was originally designed to get kids interested in coding.
Over 5 million have been sold (mostly to non-kids to play with).
It was originally designed to help kids learn PYTHON, but all
of the languages named on the previous slides are supported.
HARDWARE: Eben Upton
The idea for the Raspberry Pi came about
because the Cambridge Computer Lab saw
both a decline in the number of applicants
for their C.S. Course, and a drop in the
number that had programming experience.
Eben Upton initially hoped to sell 20,000.
Coding Example 1: Hello World!
A simple, one line program in Python, printing words to the screen:
print ("Hello World!")
Coding Example 1a: Adding Variables
Variables store data. This program asks the user their name,
then says hello to them:
name = input("What is your name? ")
print ("Hello %s!" % name)
Coding Example 1b: IF statements
IF statements let us look at variables and do different thing depending what is in them.
Note, Alex is my brother and messes with my stuff:
name = input("What is your name? ")
if name.lower() == 'katie':
print ('Katie is Awesome!')
elif name.lower() == 'alex':
print ('GO AWAY ALEX!!!')
else:
print ("Hello %s!" % name)
Coding Example 2: Fibonacci Sequence
Amongst other things Fibonacci sequence can predict bunny populations.
bunnies, baby_bunnies = (1,1)
generations = int(input('How many generations do you want? '))
for x in range(1, generations+1):
print ('Generation {} has {} baby bunnies'.format(x, baby_bunnies))
bunnies, baby_bunnies = (baby_bunnies, bunnies + baby_bunnies)
Coding Example 3: Balloon Pop!
Using a pin to pop a balloon is cheating, and uses ancient technology
import RPi.GPIO as GPIO
from time import sleep
GPIO.setup(26, GPIO.OUT)
answer = input('Do you want to pop the balloon? ')
if answer.lower() == 'yes':
GPIO.output(26, True)
sleep(10)
GPIO.output(26, False)
else:
print ('Save the balloons!')
Balloon pop circuit diagram
The transistor is being used as a switch.
When the raspberry pi turns on pin 26
the transistor switches on. This allows a
lot of current to flow through the
resistor, which gets very hot and pops
the balloon.
More Examples
As Eben Upton says, the Raspberry Pi “puts a space program
within the reach of every primary (elementary) school in the world”
The following slides show some ways Raspberry Pi's have been used.
My 3D Printer
This was the 3-D printer that I made for my
GT project and it is controlled by a
raspberry pi that lets me upload files and
control it from my iPad or other computers.
l
Pi's with Weather Balloons
Raspberry pi's have been sent up to the
edge of space in a weather balloon to take
a picture of a potato in a space ship.
More about weather balloons
o
o
o
o
o
Weather balloons can be launched for around $400.
They typically go over 100,000 feet before popping.
Flight time is usually 2-3 hours.
Usually fly 50 miles or less.
Payload can be up to 12lbs.
Quad-copter
Semi-autonomous quad-copter
that you can program your own
flight plan on.
Erica the Rhino
Erica is powered by five raspberry
pi's that allow the rhino to move it's
ears, send out and read tweets,
make rhino sounds, and even
interact with nearby smartphones.
Minecraft Pi
In Minecraft you can use python to create objects, build games, and
even link it to a webcam to take real pictures to use in the game.
Other resources
https://www.raspberrypi.org/resources/teach/
https://www.raspberrypi.org/resources/learn/
https://www.raspberrypi.org/resources/make/