Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
raspi [2014/05/15 10:16] raivo.sellraspi [2020/07/20 09:00] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ==== Raspberry Pi näitekoodid ==== ==== Raspberry Pi näitekoodid ====
  
 +http://ocr.org.uk/Images/127399-raspberry-pi-drag-drop-activity.swf
  
 === Lihtsad näited Python shell === === Lihtsad näited Python shell ===
Line 6: Line 7:
 <code c> <code c>
 5+9 5+9
- +print ("Tere Kevad")
-print (Tere Kevad) +
 56/5+99-14*9 56/5+99-14*9
- +print ("Tere Kevad")
-print (Tere Kevad) +
 3 > 7 3 > 7
- 
 for x in range (1,10): for x in range (1,10):
  print (x)  print (x)
Line 24: Line 20:
  
 <code c> <code c>
 +# -*- coding: utf-8 -*-
 kaal = float(input("Kui palju sa umbes kaalud? ")) kaal = float(input("Kui palju sa umbes kaalud? "))
 if kaal > 100: if kaal > 100:
Line 34: Line 30:
 </code> </code>
  
 +Muutke koodi nii, et:
 +  - võrreldakse näitest erinevaid suurusi
 +  - vastavalt sisendile soovitatakse kindel kaalu langetuse/tõstmise number
 +
 +=== Python graafika ===
 +<code c>
 +
 +import turtle
 +for i in range(5):
 +    turtle.forward(50)
 +    turtle.right(144)
 +import turtle
 +turtle.pencolor("#3110BE")
 +for i in range(50):
 +    turtle.forward(50)
 +    turtle.right(123)
 +turtle.pencolor("#000000")
 +</code>
 +
 +Muutke koodi nii, et:
 +  - kujundi värv oleks punane
 +  - kujund oleks suurem
 +  - tulemus oleks mõne teise kujuga
  
 === Python graafiline kasutajaliides === === Python graafiline kasutajaliides ===
 <code c> <code c>
  
-import tkinter as tk +import Tkinter as tk
 class Application(tk.Frame): class Application(tk.Frame):
     def __init__(self, master=None):     def __init__(self, master=None):
Line 45: Line 63:
         self.pack()         self.pack()
         self.createWidgets()         self.createWidgets()
- 
     def createWidgets(self):     def createWidgets(self):
         self.hi_there = tk.Button(self)         self.hi_there = tk.Button(self)
Line 51: Line 68:
         self.hi_there["command"] = self.say_hi         self.hi_there["command"] = self.say_hi
         self.hi_there.pack(side="top")         self.hi_there.pack(side="top")
- 
         self.QUIT = tk.Button(self, text="SULGE", fg="red",command=root.destroy)         self.QUIT = tk.Button(self, text="SULGE", fg="red",command=root.destroy)
         self.QUIT.pack(side="bottom")         self.QUIT.pack(side="bottom")
- 
     def say_hi(self):     def say_hi(self):
         print("Tere kevad!")         print("Tere kevad!")
- 
 root = tk.Tk() root = tk.Tk()
 app = Application(master=root) app = Application(master=root)
Line 64: Line 78:
 </code> </code>
  
 +=== LED vilgutamine ===
 +<code c>
 +import RPi.GPIO as GPIO
 +import time
 +ledPin = 11
 +GPIO.setmode(GPIO.BOARD)
 +GPIO.setup(ledPin, GPIO.OUT)
 +while True:
 +    GPIO.output(ledPin, True)
 + </code>
 +
 +Muutke koodi nii, et:
 +  - LED vilguks 1 sek. intervalliga
 +  - vastavalt kasutaja sisestatud väärtusele 0 või 1 juhitakse LED-i.
 +  - oleks graafiline kasutajaliides, millega saab LED sisse-välja lülitada
 === Valvenäide === === Valvenäide ===
 <code c> <code c>
Line 69: Line 98:
 import RPi.GPIO as GPIO import RPi.GPIO as GPIO
 import time import time
- 
 sensorPin = 7 sensorPin = 7
- 
 GPIO.setmode(GPIO.BOARD) GPIO.setmode(GPIO.BOARD)
 GPIO.setup(sensorPin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) GPIO.setup(sensorPin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
- 
-prevState = False 
-currState = False 
- 
 while True: while True:
-    time.sleep(0.1) +    time.sleep(0.1)             
-    prevState = currState +    print GPIO.input(sensorPin)
-    currState = GPIO.input(sensorPin+
-    if currState != prevState: +
-        newState = "1" if currState else "0" +
-        print "%s, %s" % (newState)+
  
 </code> </code>
 +Muutke koodi nii, et:
 +  - uus rida tuleb ainult oleku muutuse peale
 +  - lisatakse reale kuupäev ja kellaaeg, ning tulemus kirjutatakse log-i faili.
 +  - tulemused näidatakse reaalajas graafiliselt (Vihje: Reaalaja graafilise väljundi tekitamiseks  kasuta kst tarkvara)
  
 +https://www.raspberrypi.org/learning/parent-detector/worksheet/
raspi.1400148989.txt.gz · Last modified: 2020/07/20 09:00 (external edit)
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0