Raspberry Pi Workshop Kit Tutorials – 5 User Inputs

Опубликовано: 15 Июнь 2017
на канале: HiPi io
1,529
7

Welcome to the Raspberry Pi Workshop Tutorials, brought to you by ModMyPi, BuyaPi.ca, and PiShop.us. In this series, we’ll demonstrate nine projects that can be made using the YouTube Workshop Kit for Raspberry Pi. These projects are a great way to familiarize yourself with the Pi’s input and output functions, as well as creating programs in Python that we’ll use to control the Pi’s hardware.

Tutorial 5 - User Inputs
Circuit Diagram: http://www.modmypi.com/download/led_b...
Tutorial 5 Download: http://www.modmypi.com/download/youtu...
View Tutorial Online: https://www.modmypi.com/blog/youtube-...

** Code Used In This Tutorial **
NOTE - You must replace {greater than} with its corresponding symbol in both 'while count...' statements.

#!/usr/bin/python

import os
from time import sleep
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)

GPIO.setup(17,GPIO.OUT)
GPIO.setup(27,GPIO.OUT)

#Setup variables for user input
led_choice = 0
count = 0

os.system('clear')

print "Which LED would you like to blink"
print "1: Red?"
print "2: Blue?"

led_choice = input("Choose your option: ") # ask for an input

if led_choice == 1:
os.system('clear')
print "You picked the Red LED"
count = input("How many times would you like it to blink?: ")
while count {greater than} 0: # while the value of count is greater than 0
GPIO.output(27,GPIO.HIGH)
sleep(1)
GPIO.output(27,GPIO.LOW)
sleep(1)
count = count - 1 # reduce the value of count by 1

if led_choice == 2:
os.system('clear')
print "You picked the Blue LED"
count = input("How many times would you like it to blink?: ")
while count {greater than} 0: # while the value of count is greater than 0
GPIO.output(17,GPIO.HIGH)
sleep(1)
GPIO.output(17,GPIO.LOW)
sleep(1)
count = count - 1 # reduce the value of count by 1


На этой странице сайта вы можете посмотреть видео онлайн Raspberry Pi Workshop Kit Tutorials – 5 User Inputs длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь HiPi io 15 Июнь 2017, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 1,529 раз и оно понравилось 7 зрителям. Приятного просмотра!