O slideshow foi denunciado.
Seu SlideShare está sendo baixado. ×

Intro to Python with GPIO

Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Próximos SlideShares
Intro to Python
Intro to Python
Carregando em…3
×

Confira estes a seguir

1 de 12 Anúncio

Mais Conteúdo rRelacionado

Diapositivos para si (20)

Semelhante a Intro to Python with GPIO (20)

Anúncio

Mais de primeteacher32 (20)

Mais recentes (20)

Anúncio

Intro to Python with GPIO

  1. 1. Introduction to PythonIntroduction to Python ProgrammingProgramming
  2. 2. Why Python?Why Python?  Python is what is referred to as an object-oriented programming language (OOP)  Python is a general purpose programming language. That means you can use Python to write code for a number of programming tasks. ◦ Google search engine ◦ Gaming ◦ Processing financial transactions ◦ Data Analytics ◦ Physical Programming  Simple  Less Syntax  Extensive User Community  Interpreted
  3. 3. Interpreted?Interpreted? Python is interpreted, which means that python code is translated and executed by an interpreter one statement at a time. This means you can run commands/code on the command prompt… Through a command prompt with a text file… Using an IDE
  4. 4. What Does It Look Like?What Does It Look Like?
  5. 5. Parts of a Python ProgramParts of a Python Program Def: Source Code is the program text entered into an interpreter by the programmer. ◦ The saved file is referred to as, the source file. ◦ The main file in a python program, called main ◦ Can program on the command prompt The extension to a python source file is “.py” ◦ Xcel - .xls ◦ Power Point - .ppt Two main parts to a source file ◦ Modules ◦ Main code
  6. 6. Good Programming ProclamationsGood Programming Proclamations Using comments to denote programs or sections of code ◦ A comment beginning with # is called a single-line comment because it terminates at the end of the current line. ◦ You also may use a multi-line comment—possibly containing many lines—begins with ’’’ and ends with ’’’. You use blank lines, space characters and tab characters (i.e., “tabs”) to make programs easier to read. ◦ Together, these characters are known as white space. ◦ White-space characters are USUALLY ignored by the interpreter. ◦ Python has its own rules with white space
  7. 7. ModulesModules  A module is a python source file that has prewritten python code.  These predefined files allow users to utilize code that has been previously developed. ◦ Don’t have to recreate the wheel, just use the wheel and improve on the technology.  math  time  gpiozero  os  Code: Importing modules  import module_name  from module_name import class_name
  8. 8. ExpressionsExpressions • A programming expression is a combination of symbols to represent a value. • One side of an equation • Ex. • 5+7 • False • print() • led.on()
  9. 9. Printing a Line of TextPrinting a Line of Text print(“ “) Anything placed inside the quotes will be printed on the screen upon execution of the print command.
  10. 10. Manipulating TimeManipulating Time The time module is a popular module which provides functions for working with times and converting between them. ◦ sleep ◦ local time ◦ epoch time Code: ◦ Importing time module  import time ◦ Using time functions  time.sleep(#)  time.localtime(time.time())
  11. 11. Manipulating LED’sManipulating LED’s  The Raspberry Pi comes with a library RPi.GPIO that allow the manipulation of GPIO pins: ◦ Setup pins as inputs or outputs ◦ Read inputs, Set output levels ◦ Cleanup  Code: ◦ Importing gpio module  import RPi.GPIO as GPIO  GPIO.setmode(GPIO.BCM) ◦ Setup an LED  GPIO.setup(pin#, GPIO.OUT) ◦ Using led functions  GPIO.output(pin#,GPIO.HIGH)  GPIO.output(pin#,GPIO.LOW)
  12. 12. CheckpointCheckpoint 1. What is an IDE? 2. What is a comment and its importance? 3. How is white space used in programming? 4. What are modules? 5. Name 2 modules

Notas do Editor

  • Common elements in programming languages:
    Key Words
    Programmer-Defined Identifiers
    Operators
    Punctuation
    Syntax
  • Where have you heard of expressions before? Math class and what were they
  • Cleanup()

×