ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [4ํšŒ์ฐจ-1] ๋ผ์ฆˆ๋ฒ ๋ฆฌํŒŒ์ด GPIO ์‹ค์Šต - 2
    ๋กœ๋ด‡๊ต์œก/4ํšŒ์ฐจ_๋ผ์ฆˆ๋ฒ ๋ฆฌGPIO 2020. 9. 10. 23:55

    1. ๋ฒ„ํŠผ ์‹ค์Šต

     ๊ฐ€. ๋ฒ„ํŠผ

     

    ํ‘ธ์‰ฌ ๋ฒ„ํŠผ

      ๋ฒ„ํŠผ(์Šค์œ„์น˜)์€ ์ „๊ธฐ์˜ ํ๋ฆ„์„ ์ž‡๊ฑฐ๋‚˜ ๋Š๊ธฐ ์œ„ํ•œ ์ œ์–ด์žฅ์น˜์ด๋ฉฐ, ์กฐ๋ช…์ด๋‚˜ ์ปดํ“จํ„ฐ ๋“ฑ์„ ๋„๊ฑฐ๋‚˜ ์ผค ๋•Œ ๋ˆ„๋ฅด๋Š” ๋ฒ„ํŠผ๋„ ์Šค์œ„์น˜์˜ ์ผ์ข…์ž…๋‹ˆ๋‹ค. ์šฐ๋ฆฌ๊ฐ€ ์‚ฌ์šฉํ•  ํ‘ธ์‰ฌ ๋ฒ„ํŠผ์€ ์ƒ๋‹จ์˜ ๋ฒ„ํŠผ ๋ถ€๋ถ„๊ณผ ํ•˜๋‹จ์˜ ๋‹ค๋ฆฌ(4)๊ฐœ๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด์ง€ ์•Š์•„๋„ A-C, B-D๋Š” ์—ฐ๊ฒฐ์ด ๋˜์–ด ์žˆ๋Š” ์ƒํƒœ์ด๋ฉฐ, ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅผ ๋•Œ A-B-C-D๊ฐ€ ๋ชจ๋‘ ์—ฐ๊ฒฐ๋˜์–ด ์ „๊ธฐ๊ฐ€ ํ๋ฅด๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

     

     

     ๋‚˜. ํšŒ๋กœ ๊ตฌ์„ฑ

     

      ๋ฒ„ํŠผ์„ ์ด์šฉํ•˜์—ฌ LED๋ฅผ ์ผค ์ˆ˜ ์žˆ๋„๋ก ํšŒ๋กœ๋ฅผ ๊ตฌ์„ฑํ•˜์—ฌ ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

     

      ์ค€๋น„๋ฌผ  ๋ฒ„ํŠผ, ์ „์„ , (+LED, ์ „์„ , ์ €ํ•ญ330Ω์œผ๋กœ ๊ตฌ์„ฑ๋œ ํšŒ๋กœ)

     

    ์ค€๋น„๋ฌผ


    ๋ฒ„ํŠผ์˜ ์œ„์น˜ ์ฃผ์˜

      ์ง€๋‚œ ์‹œ๊ฐ„์— ๋งŒ๋“  LED ํšŒ๋กœ์— ๋ฒ„ํŠผ์„ ์ถ”๊ฐ€๋กœ ๊ตฌ์„ฑํ•˜์—ฌ ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ๋ฒ„ํŠผ์˜ ๋‹ค๋ฆฌ ๋ชจ์–‘์— ์ฃผ์˜ํ•˜๋ฉฐ ๋ธŒ๋ ˆ๋“œ๋ณด๋“œ์— ๋ผ์›Œ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ๋ฒ„ํŠผ์„ ๋ฐ”๋ฅด๊ฒŒ ๋ผ์šฐ๋ฉด ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๊ธฐ ์ „์—๋Š” ํšŒ๋กœ๊ฐ€ ๋Š์–ด์ ธ ์žˆ์–ด ์ „๊ธฐ๊ฐ€ ํ๋ฅด์ง€ ์•Š์œผ๋ฉฐ ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๊ฒŒ ๋˜๋ฉด ์ „๊ธฐ ํšŒ๋กœ๊ฐ€ ์—ฐ๊ฒฐ๋ฉ๋‹ˆ๋‹ค. ์ด๋ฅผ ์ด์šฉํ•˜์—ฌ ํŒŒ์ด์ฌ์—์„œ ์ž…๋ ฅ ์‹ ํ˜ธ๋ฅผ ๋ฐ›์Šต๋‹ˆ๋‹ค. 

     

    ๋ฒ„ํŠผ ์žฅ์ฐฉ
    ๋ฒ„ํŠผ์˜ ๋‹ค๋ฆฌ์™€ ์—ฐ๊ฒฐ๋˜๋Š” ์ „์„  ์—ฐ๊ฒฐ
    ๋ฒ„ํŠผ์˜ ๋‹ค๋ฆฌ์™€ ์—ฐ๊ฒฐ๋˜๋Š” ์ „์„  ์—ฐ๊ฒฐ

      ๋ฒ„ํŠผ์˜ ๋‹ค๋ฆฌ์™€ ํšŒ๋กœ๋ฅผ ๊ตฌ์„ฑํ•ฉ๋‹ˆ๋‹ค. ํ•œ ์ชฝ ๋‹ค๋ฆฌ์™€ Gnd๋ฅผ ์ „์„ ์œผ๋กœ ์—ฐ๊ฒฐํ•˜๋ฉฐ, ๋‚˜๋จธ์ง€ ๋‹ค๋ฆฌ๋Š” GPIO 16๋ฒˆ์— ์ „์„ ์œผ๋กœ ์—ฐ๊ฒฐํ•ฉ๋‹ˆ๋‹ค.  ๋ฒ„ํŠผ์—๋Š” ๋”ฐ๋กœ ๊ทน์ด ์—†์œผ๋ฏ€๋กœ ๋‹ค๋ฆฌ์˜ ์ˆœ์„œ์™€ ๊ด€๊ณ„์—†์ด Gnd์™€ GPIO 16๋ฒˆ์— ์ž˜ ์—ฐ๊ฒฐ๋งŒ ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

     

    ๋ฒ„ํŠผ๊ณผ LED ํšŒ๋กœ ๊ตฌ์„ฑ#1 ํšŒ๋กœ ์™„์„ฑ
    ๋ฒ„ํŠผ๊ณผ LED ํšŒ๋กœ ๊ตฌ์„ฑ#2 ํšŒ๋กœ ์™„์„ฑ

      ๊ธฐ์กด์— GPIO 13๋ฒˆ์— ์—ฐ๊ฒฐ๋œ LEDํšŒ๋กœ์— ๋ฒ„ํŠผํšŒ๋กœ๋ฅผ ์ถ”๊ฐ€ํ•˜์—ฌ ์™„์„ฑํ•˜์˜€์Šต๋‹ˆ๋‹ค. ๋‹ค์Œ์—๋Š” ๋ฒ„ํŠผ์œผ๋กœ LED๋ฅผ ์ œ์–ดํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

     

     

     ๋‹ค. ํ”„๋กœ๊ทธ๋ž˜๋ฐ

     

    ์˜ˆ์ œ ์†Œ์Šค(5-led_button.py)
    from gpiozero import LED, Button 
    from signal import pause 

    led = LED(13
    button = Button(16)

    button.when_pressed = led.on
    button.when_released = led.off

    pause()

     

    ์˜ˆ์ œ ์†Œ์Šค(5-led_button2.py)
    from gpiozero import LED, Button 
    from signal import pause 

    led = LED(13
    button = Button(16)

    led.source = button

    pause()

     

    2. ์›€์ง์ž„ ๊ฐ์ง€ ์‹ค์Šต

     

     ๊ฐ€. ์ธ์ฒด ๊ฐ์ง€ ์„ผ์„œ(PIR์„ผ์„œ)

     

    HC-SR501

      ์ธ์ฒด ๊ฐ์ง€ ์„ผ์„œ(PIR์„ผ์„œ, Passive Infrared Sensor)๋ž€ ์‚ฌ๋žŒ์ด๋‚˜ ๋™๋ฌผ์ด ์›€์ง์ผ ๋•Œ ๋ฐœ์ƒ๋˜๋Š” ์ ์™ธ์„  ๋ณ€ํ™”๋ฅผ ๊ฐ์ง€ํ•ด ๋‚ด๋Š” ์„ผ์„œ๋กœ์„œ ๋ชจ์…˜ ์„ผ์„œ๋ผ๊ณ ๋„ ํ•ฉ๋‹ˆ๋‹ค. ์ผ์ƒ ์ƒํ™œ์— ํ”ํ•˜๊ฒŒ ์‚ฌ์šฉ๋˜๋Š” ์‚ฌ๋ก€๋Š” ํ˜„๊ด€์ด๋‚˜ ์—˜๋ฆฌ๋ฒ ์ดํ„ฐ ์ž…๊ตฌ์—์„œ ์‚ฌ๋žŒ์ด ์ ‘๊ทผํ•˜๋ฉด ์ž๋™์œผ๋กœ ๋ถˆ์ด ์ผœ์ง€๋Š” ์ „๋“ฑ์ด ์žˆ์Šต๋‹ˆ๋‹ค.

     

      ์›€์ง์ž„์„ ๊ฐ์ง€ํ•˜๋ฏ€๋กœ ์›€์ง์ž„์ด ์—†์œผ๋ฉด ๋‹น์—ฐํžˆ ๋ฐ˜์‘ํ•˜์ง€ ์•Š์œผ๋ฉฐ ๊ฐ€๋ณ€์ €ํ•ญ์„ ์ด์šฉํ•˜์—ฌ ๊ฐ๋„์™€ ๊ฐ์ง€ ์‹œ๊ฐ„ ๋“ฑ์˜ ์กฐ์ ˆ์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค์ „์› 2ํ•€(VCC/GND)๊ณผ ์‹ ํ˜ธ๋ถ€(SIG) ๋“ฑ ์ด 3๊ฐœ์˜ ํ•€์„ ์‚ฌ์šฉํ•˜๋ฉฐ, ์ฃผ๋ณ€์˜ ์›€์ง์ž„์ด ์ธ์‹๋˜๋ฉด ์‹ ํ˜ธ๋ถ€๋กœ ์ถœ๋ ฅ์ด ๋‚˜์˜ค๋Š” ํ˜•ํƒœ์ž…๋‹ˆ๋‹ค. ์ถœ๋ ฅ์€ HIGH, LOW๋กœ ๋””์ง€ํ„ธ ์ถœ๋ ฅ๊ฐ’์„ ๊ฐ€์ง‘๋‹ˆ๋‹ค.

     

    HC-SR501

    ์„ผ์„œ ๊ฐ๋„ ์กฐ์ ˆ(Distance Adjust)  ์‹œ๊ณ„๋ฐฉํ–ฅ์œผ๋กœ ๋Œ๋ฆฌ๋ฉด, ๋ฏผ๊ฐ๋„๊ฐ€ ๋‚ฎ์•„์ ธ์„œ ๊ฐ์ง€ ๊ฑฐ๋ฆฌ๊ฐ€ ์ค„์–ด๋“ญ๋‹ˆ๋‹ค.

     

    ์ง€์—ฐ ์‹œ๊ฐ„ ์กฐ์ ˆ(Delay Time Adjust)  ์ธ์ฒด ๊ฐ์ง€ ํ›„ ๊ฐ์ง€๋œ ์ƒํƒœ๋ฅผ ์–ผ๋งˆ๊ฐ„ ์œ ์ง€ํ•  ๊ฒƒ์ธ๊ฐ€ ํ•˜๋Š” ์‹œ๊ฐ„์„ ์กฐ์ ˆํ•ฉ๋‹ˆ๋‹ค. ์‹œ๊ณ„๋ฐฉํ–ฅ(์ง€์—ฐ์‹œ๊ฐ„ ์งง๊ฒŒ), ๋ฐ˜์‹œ๊ณ„๋ฐฉํ–ฅ(์ง€์—ฐ์‹œ๊ฐ„ ๊ธธ๊ฒŒ)

     

    ํŠธ๋ฆฌ๊ฑฐ ๋ชจ๋“œ  ์ขŒ์ธก์˜ ์ ํผ์Šค์œ„์น˜๋ฅผ L๋กœ ์—ฐ๊ฒฐํ•˜๋ฉด ๊ฐ์ง€ ์‹ ํ˜ธ๋ฅผ ํ•œ ๋ฒˆ๋งŒ ๋ณด๋‚ด์ฃผ๋Š” ๋ชจ๋“œ์ด๊ณ , H๋Š” ๊ฐ์ง€์‹ ํ˜ธ๋ฅผ ๊ณ„์†ํ•ด์„œ ๋ณด๋‚ด์ฃผ๋Š” ๋ชจ๋“œ์ž…๋‹ˆ๋‹ค.

     

     

     ๋‚˜. ํšŒ๋กœ ๊ตฌ์„ฑ

     

      PIR์„ผ์„œ๋ฅผ ์ด์šฉํ•˜์—ฌ ์›€์ง์ž„์ด ๊ฐ์ง€๋˜๋ฉด LED๊ฐ€ ์ผœ์ง€๋„๋ก ํšŒ๋กœ๋ฅผ ๊ตฌ์„ฑํ•˜์—ฌ ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

     

      ์ค€๋น„๋ฌผ PIR์„ผ์„œ, MF์ „์„ , (+LED, ์ „์„ , ์ €ํ•ญ330Ω์œผ๋กœ ๊ตฌ์„ฑ๋œ ํšŒ๋กœ)

     

    ์ค€๋น„๋ฌผ


    ์ปค๋ฒ„๋ฅผ ์ œ๊ฑฐํ•œ PIR์„ผ์„œ ๋ชจ์Šต

      ์ปค๋ฒ„๋ฅผ ์ œ๊ฑฐํ•˜์—ฌ PIR์„ผ์„œ๋ฅผ ์‚ดํŽด๋ณด๋ฉด VCC-OUT-GND๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ๋Š” ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค. PIR์„ผ์„œ๊ฐ€ ๋™์ž‘ํ•˜๋ ค๋ฉด 5~12V์˜ ์ž…๋ ฅ์ „์••์ด ํ•„์š”ํ•˜๋ฏ€๋กœ ๋ผ์ฆˆ๋ฒ ๋ฆฌํŒŒ์ด์˜ GPIO์—์„œ 5V ์ „์›์— VCC๋ฅผ ์—ฐ๊ฒฐํ•˜์—ฌ์•ผ ํ•œ๋‹ค.

      GND๋Š” ๋ธŒ๋ ˆ๋“œ๋ณด๋“œ GND(-๊ทน)์— ์—ฐ๊ฒฐํ•˜๋ฉฐ OUT์€ ์›€์ง์ž„์„ ๊ฐ์ง€ํ•˜์—ฌ ์‹ ํ˜ธ๋ฅผ ๋ณด๋‚ด์ฃผ๋Š” ๋ถ€๋ถ„์ด๋ฏ€๋กœ ์ด๋ฅผ GPIO 24๋ฒˆ์— ์—ฐ๊ฒฐํ•˜์—ฌ ์‹ ํ˜ธ๋ฅผ ๋ฐ›๋Š”๋‹ค.

     

    VCC-OUT-GND ์—ฐ๊ฒฐํ•˜๊ธฐ#1

      ์ „์„ ์„ ๊ฐ๊ฐ์˜ ํ•€์— ์—ฐ๊ฒฐํ•ฉ๋‹ˆ๋‹ค. ๊ทœ์น™์„ ์ •ํ•ด VCC๋Š” ๋นจ๊ฐ„์ƒ‰, GND๋Š” ์–ด๋‘์šด์ƒ‰, OUT์€ ์ค‘๊ฐ„์ƒ‰์œผ๋กœ ์—ฐ๊ฒฐํ•ด์ค๋‹ˆ๋‹ค. ์ด๋Ÿฐ ๋ฐฉ์‹์œผ๋กœ ์ „์„ ์„ ์—ฐ๊ฒฐํ•˜๋ฉด ๊ฐ๊ฐ์˜ ์ „์„ ์ด ํ•˜๋Š” ์—ญํ• ์„ ์‰ฝ๊ฒŒ ํŒŒ์•…ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

     

    VCC-OUT-GND ์—ฐ๊ฒฐํ•˜๊ธฐ#2

      PIR์„ผ์„œ์— ์—ฐ๊ฒฐ๋œ ์ „์„ ์—์„œ VCC(5V)์™€ GND๋ฅผ ์ •ํ™•ํžˆ ํ™•์ธํ•˜์—ฌ ์—ฐ๊ฒฐํ•˜์—ฌ ์ค๋‹ˆ๋‹ค.

     

    VCC-OUT-GND ์—ฐ๊ฒฐํ•˜๊ธฐ#3

      PIR์„ผ์„œ์—์„œ OUT๊ณผ ์—ฐ๊ฒฐ๋œ ์ „์„ ์„ GPIO 24๋ฒˆ์— ์—ฐ๊ฒฐํ•˜์—ฌ ์ค๋‹ˆ๋‹ค.

     

    PIR์„ผ์„œ์™€ LED ํšŒ๋กœ ๊ตฌ์„ฑ#1 ํšŒ๋กœ ์™„์„ฑ
    PIR์„ผ์„œ์™€ LED ํšŒ๋กœ ๊ตฌ์„ฑ#2 ํšŒ๋กœ ์™„์„ฑ

     

     

    ๋‹ค. ํ”„๋กœ๊ทธ๋ž˜๋ฐ

     

    ์˜ˆ์ œ ์†Œ์Šค(6-led_motion.py)
    from gpiozero import MotionSensor, LED
    from signal import pause 

    pir = MotionSensor(24)
    led = LED(13

    pir.when_motion = led.on

    pir.when_no_motion = led.off

    pause()

     

     

    2. 3์ƒ‰ LED ์‹ค์Šต

     

     ๊ฐ€. 3์ƒ‰ LED

     

    3์ƒ‰ RGB

      3์ƒ‰ LED๋Š” ์ด์ „์— ์‚ฌ์šฉํ•œ LED์™€ ๋‹ฌ๋ฆฌ 4๊ฐœ์˜ ํ•€์ด ์žˆ์–ด ๊ฐ๊ฐ์˜ ํ•€์ด R(Red), G(Green), B(Blue), Gnd์ž…๋‹ˆ๋‹ค. R, G, B ํ•€์— ๊ฐ’์„ ๋„ฃ์–ด ์ƒ‰์„ ์กฐํ•ฉํ•˜์—ฌ ํ‘œํ˜„ํ•  ์ˆ˜ ์žˆ์–ด ๋‹ค์–‘ํ•œ ์ƒ‰ ํ‘œํ˜„์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

     

     

     ๋‚˜. ํšŒ๋กœ ๊ตฌ์„ฑ

     

      3์ƒ‰ LED๋ฅผ ํŒŒ์ด์ฌ์œผ๋กœ ์ œ์–ดํ•˜์—ฌ ๋‹ค์–‘ํ•œ ์ƒ‰์„ ํ‘œํ˜„ํ•˜๋Š” ํšŒ๋กœ๋ฅผ ๊ตฌ์„ฑํ•˜์—ฌ ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

     

      ์ค€๋น„๋ฌผ 3์ƒ‰ LED, ์ „์„ , ์ €ํ•ญ330Ω

     

      ์ฐธ๊ณ  ์ €ํ•ญ์€ ์ €ํ•ญ์ด ์žˆ๋Š” 3์ƒ‰ LED๋ชจ๋“ˆ์„ ์‚ฌ์šฉํ•˜๋ฉด ์—ฐ๊ฒฐํ•˜์ง€ ์•Š์•„๋„ ๋ฉ๋‹ˆ๋‹ค. ์‚ฌ์ง„์— ๋ณด์ด๋Š” 3์ƒ‰ LED๋ชจ๋“ˆ์€ ์ €ํ•ญ์ด ์žˆ์ง€๋งŒ ์ดํ•ด๋ฅผ ๋•๊ธฐ ์œ„ํ•ด ์ €ํ•ญ์„ ์—ฐ๊ฒฐํ•˜์—ฌ Gnd๋ฅผ ํ‘œํ˜„ํ•˜๊ณ ์ž ํ•ฉ๋‹ˆ๋‹ค.

     

    ์ค€๋น„๋ฌผ


    GPIO 4, 5, 6๋ฒˆ ์—ฐ๊ฒฐ

      ๋ธŒ๋ ˆ๋“œ๋ณด๋“œ์—์„œ ์ „์„ ์„ ์ด์šฉํ•˜์—ฌ GPIO 4, 5, 6๊ณผ ์—ฐ๊ฒฐํ•ฉ๋‹ˆ๋‹ค. GPIO 4๋ฒˆ์€ R์„ ํ‘œํ˜„ํ•˜๋Š” Red ์ „์„ ์„ ์ด์šฉํ•˜์˜€๊ณ , GPIO 5๋ฒˆ์€ G๋ฅผ ํ‘œํ˜„ํ•˜๋Š” Green ์ „์„ ์ด ์—†์–ด Orange๋กœ ์˜๋ฏธ๋ฅผ ๋Œ€์ฒดํ•ด์„œ ์‚ฌ์šฉํ–ˆ์Šต๋‹ˆ๋‹ค. GPIO 6๋ฒˆ์€ B๋ฅผ ํ‘œํ˜„ํ•˜๋Š” Blue ์ „์„ ์ด ์—†์–ด Black์œผ๋กœ ์˜๋ฏธ๋ฅผ ๋Œ€์ฒดํ•˜์—ฌ ์‚ฌ์šฉํ–ˆ์Šต๋‹ˆ๋‹ค. ์ „์„ ์„ ์—ฐ๊ฒฐํ•  ๋•Œ ๊ทœ์น™์„ ์ฃผ์–ด ์—ฐ๊ฒฐํ•˜๋ฉด ์ดํ•ดํ•˜๊ธฐ ์‰ฝ์Šต๋‹ˆ๋‹ค.

     

    GPIO 4, 5, 6๊ณผ ์ €ํ•ญ ์—ฐ๊ฒฐ

      ์ €ํ•ญ์˜ ํ•œ ์ชฝ์„ Gnd์— ์—ฐ๊ฒฐํ•ฉ๋‹ˆ๋‹ค. ์ „์„ ์˜ ๋ฐ˜๋Œ€์ชฝ์„ ๋ธŒ๋ ˆ๋“œ๋ณด๋“œ์— ์‚ฌ์ง„์ฒ˜๋Ÿผ ์ฐจ๋ก€๋Œ€๋กœ ์—ฐ๊ฒฐํ•ฉ๋‹ˆ๋‹ค. GPIO 6 - GPIO 5 - GPIO 4 - ์ €ํ•ญ(Gnd) ์ˆœ์œผ๋กœ ํ•œ ์นธ์”ฉ ์˜†์— ์—ฐ๊ฒฐํ•ฉ๋‹ˆ๋‹ค.

     

    3์ƒ‰ LED์˜ 4ํ•€
    3์ƒ‰ LED ๋ธŒ๋ ˆ๋“œ๋ณด๋“œ ์—ฐ๊ฒฐ

     

    3์ƒ‰ LED ํšŒ๋กœ ๊ตฌ์„ฑ#1 ํšŒ๋กœ ์™„์„ฑ
    3์ƒ‰ LED ํšŒ๋กœ ๊ตฌ์„ฑ#2 ํšŒ๋กœ ์™„์„ฑ

     

     

    ๋‹ค. ํ”„๋กœ๊ทธ๋ž˜๋ฐ

     

    ์˜ˆ์ œ ์†Œ์Šค(7-full_color_led.py)
    from gpiozero import RGBLED
    from time import sleep

    led = RGBLED(red=4, green=5, blue=6)

    led.red = 1
    sleep(1)
    led.red = 0.5
    sleep(1)
    led.red = 0
    sleep(1)

    led.green = 1
    sleep(1)
    led.green = 0.5
    sleep(1)
    led.green = 0
    sleep(1)

    led.blue = 1
    sleep(1)
    led.blue = 0.5
    sleep(1)
    led.blue = 0
    sleep(1)

    led.red = 1
    led.green = 1
    led.blue = 1
    sleep(1)
    led.red = 0
    led.green = 0
    led.blue = 0
    sleep(1)

     

    ์˜ˆ์ œ ์†Œ์Šค(7-full_color_led2.py)
    from gpiozero import RGBLED
    from time import sleep

    led = RGBLED(red=4, green=5, blue=6)

    led.color = (0, 1, 0)     # full green
    sleep(1)
    led.color = (1, 0, 1)     # magenta
    sleep(1)
    led.color = (1, 1, 0)     # yellow
    sleep(1)
    led.color = (0, 1, 1)     # cyan
    sleep(1)
    led.color = (1, 1, 1)     # white
    sleep(1)
    led.color = (0, 0, 0)     # off
    sleep(1)

     

    ์˜ˆ์ œ ์†Œ์Šค(7-full_color_led3.py)
    from gpiozero import RGBLED
    from time import sleep

    led = RGBLED(red=4, green=5, blue=6)

    for i in range(100):
        led.blue = i/100
        sleep(0.05)

    led.blue = 0
    sleep(0.1)

     

     

    ์‹ค์Šต) ์ง€๊ธˆ๊นŒ์ง€ ๋ฐฐ์šด ๋‚ด์šฉ์„ ๋ฐ”ํƒ•์œผ๋กœ ๋‚˜๋งŒ์˜ ์ „์ž ํšŒ๋กœ๋ฅผ ๊ตฌ์„ฑํ•˜์—ฌ ํ”„๋กœ๊ทธ๋žจ์„ ๋งŒ๋“ค์–ด๋ด…์‹œ๋‹ค.

    '๋กœ๋ด‡๊ต์œก > 4ํšŒ์ฐจ_๋ผ์ฆˆ๋ฒ ๋ฆฌGPIO' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

    [gpiozero] RGBLED, MotionSensor  (0) 2021.06.25

    ๋Œ“๊ธ€

Designed by Tistory.