練習[Raspberry Pi]

9107 ワード

1.led電球で実習



[ led1.py ]

import RPi.GPIO as GPIO
import time
import  warnings
warnings.filterwarnings("ignore")

GPIO.setmode(GPIO.BCM)
GPIO.setup(17,GPIO.OUT)


GPIO.output(17,False)
print("GPIO.output(17,False)")
time.sleep(3)
GPIO.output(17,True)
print("GPIO.output(17,True)")
time.sleep(3)
GPIO.cleanup() 
[ led2.py ]

import RPi.GPIO as GPIO
import time
import  warnings
warnings.filterwarnings("ignore")

GPIO.setmode(GPIO.BCM)
GPIO.setup(17,GPIO.OUT)

while(True):
    GPIO.output(17,False)
    print("GPIO.output(17,False)")
    time.sleep(3)
    GPIO.output(17,True)
    print("GPIO.output(17,True)")
    time.sleep(3)

2.カメラの接続/撮影

sudo apt-get update
sudo apt-get upgrade

sudo apt-get install python-picamera

sudo rpi-update

raspistill -v -o picameratest.jpg  
//현재 디렉토리에 picameratest.jpg로 찍혀있다.

mkdir cctv
cd cctv

sudo nano cctv.py
//nano편집기로 python파일을 만들고 아래의 카메라 조정 소스코드를 입력해
조작한다.
import picamera, time
import datetime
Camera = picamera.PiCamera()
Camera.resolution=(600,450) 
Camera.start_preview() 


def Camera2():

    input("Enter 키를 누르세요")
    print("촬영 시작")
    time.sleep(3)
    
    now = datetime.datetime.now()
    time1 = now.strftime('Pic%Y-%m-%d_%H%M%S')
    time2=time1+'.jpg'
    print("파일 명 : %s" %(time2))
    Camera.capture(time2)
try:
    while True:
        Camera2()       
except KeyboardInterrupt:
    print("")
    Camera.stop_preview() 
    print("촬영종료")

2-1. カメラがクランクインするとled電球が開きます



3.接続ファン回転