目錄

  1. 實驗概述
  2. 實驗原理
  3. 代碼編寫

1.實驗概述

使用樹莓派上的pythonm語言,編寫出一個小程式,控制PWR.A53板上的三個LED燈閃爍,經由這個實驗,可以學到最基本的1/0口控制,延時函數,python控制樹莓派IO工作原理等。

2.實驗原理

LED燈是一種基本的發光器,給它輸入5V電壓時,它就會亮,給它0V時它就熄滅,這次實驗,利用PWR.A53板上的LED燈LED0、LED1、LED2三個燈,這三個燈分別接到10、9、25三個IO管腳(BCM模式),只要在程式裡改變那些腳位輸出電流,就可以讓LED燈閃爍的效果。下方圖示為腳位分布圖

3.代碼編寫

  • 設定LED的腳位(LED0=10)
  • 將GPIO設定為輸出模式,和起始電流(HIGH)或( LOW)
  • 代碼為: GPIO.steup(LED0, GPIO.OUT,initia= GPIO.HIGH )
  • 使用GPIO.output()函數,把LED0這個腳位電流拉低
  • 代碼為: GPIO.output(LED0,False)

程式如下

import time

import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)

LED0=10

LED1=9

LED2=25

GPIO.setwarnings(False)

GPIO.setup(LED0,GPIO.OUT,initial=GPIO.HIGH)##led

GPIO.setup(LED1,GPIO.OUT,initial=GPIO.HIGH)##led

GPIO.setup(LED2,GPIO.OUT,initial=GPIO.HIGH)##led

def init_light():

        GPIO.output(LED0,False)

        GPIO.output(LED1,False)

        GPIO.output(LED2,False)

        time.sleep(0.5)

        GPIO.output(LED0,True)

        GPIO.output(LED1,False)

        GPIO.output(LED2,False)

        time.sleep(0.5)

        GPIO.output(LED0,False)

        GPIO.output(LED1,True)

        GPIO.output(LED2,False)

        time.sleep(0.5)

        GPIO.output(LED0,False)

        GPIO.output(LED1,False)

        GPIO.output(LED2,True)

        time.sleep(0.5)

        GPIO.output(LED0,False)

        GPIO.output(LED1,False)

        GPIO.output(LED2,False)

        time.sleep(0.5)

        GPIO.output(LED0,False)

        GPIO.output(LED1,False)

        GPIO.output(LED2,False)

for i in range(1,5):

        init_light()

299 thoughts on “樹莓派(Raspberry Pi)從零開始 -8. LED閃爍實驗

  1. I simply couldn’t depart your site before suggesting that I actually loved the
    standard information a person provide for your guests?
    Is gonna be back steadily to check up on new posts

  2. Wonderful blog! I found it while surfing around on Yahoo News.
    Do you have any tips on how to get listed in Yahoo News?
    I’ve been trying for a while but I never seem to get there!

    Appreciate it

  3. Greetings I am so happy I found your site, I really found you by error, whileI was searching on Yahoo for something else, Anyways I am here now and would just like to say thanks a lot for a incredible postand a all round thrilling blog (I also love the theme/design), I don’t have time to look over it allat the moment but I have bookmarked it and also included your RSSfeeds, so when I have time I will be back to read more, Pleasedo keep up the excellent work.

  4. I like the valuable information you provide in your
    articles. I’ll bookmark your weblog and check again here regularly.
    I’m quite sure I will learn plenty of new stuff right
    here! Best of luck for the next!

  5. My brother recommended I would possibly like this web site.He was totally right. This post actually made my day. You can not imaginejust how a lot time I had spent for this information! Thanks!

  6. My coder is trying to persuade me to move to .net from PHP.
    I have always disliked the idea because of the expenses.
    But he’s tryiong none the less. I’ve been using Movable-type
    on various websites for about a year and am concerned about switching to another platform.
    I have heard fantastic things about blogengine.net.

    Is there a way I can import all my wordpress posts into it?
    Any kind of help would be really appreciated!

  7. Attractive component to content. I simply stumbled upon your site and in accession capital to assert that I
    get in fact enjoyed account your weblog posts. Any way I will be subscribing to your feeds and even I success you get admission to constantly
    rapidly.

  8. We are a group of volunteers and opening a new scheme in our community.
    Your site provided us with valuable information to work on. You have done a
    formidable job and our entire community will
    be grateful to you.

  9. Olá !! Ainda que não seja relacionado ao texto, mas sim dosite , gostaria comentar que seu template é ótimo .gostei muito de navegar nele . Tem muito site por aí que apesarde ter ótimos artigos é tão chato de navegar, que saímos fora .Sucesso !

  10. I enjoy what you guys tend to be up too. This sort of clever work and exposure!Keep up the great works guys I’ve incorporated you guys to blogroll.

  11. If you are going for most excellent contents like I do,
    just pay a visit this web site every day for the reason that
    it presents quality contents, thanks

  12. Hey I know this is off topic but I was wondering
    if you knew of any widgets I could add to my blog that automatically tweet my newest twitter
    updates. I’ve been looking for a plug-in like this for quite some time and was hoping maybe you
    would have some experience with something
    like this. Please let me know if you run into anything.
    I truly enjoy reading your blog and I look forward to your new updates.

  13. After looking into a handful of the blog articles on your website, I truly appreciate your way of writing a blog.I bookmarked it to my bookmark webpage list and will be checking back soon. Please check out my web site as well and let me know your opinion.

  14. I just could not leave your web site before suggesting that I really loved the standard
    information a person provide to your guests?
    Is going to be again frequently to check up on new posts

  15. Hey there just wanted to give you a quick heads up and let you know
    a few of the pictures aren’t loading properly.
    I’m not sure why but I think its a linking issue. I’ve tried it in two
    different web browsers and both show the same results.

  16. Definitely consider that which you stated. Your favorite justification appeared to be at
    the net the easiest factor to be mindful of. I say to you,
    I certainly get annoyed whilst other folks
    consider worries that they plainly don’t understand about.
    You controlled to hit the nail upon the top and outlined
    out the entire thing with no need side effect ,
    people could take a signal. Will probably be again to get more.
    Thanks

  17. I’ve read a few good stuff here. Definitely worth bookmarking for revisiting.

    I wonder how a lot attempt you place to create this kind of
    wonderful informative website.

  18. You really make it seem so easy with your presentation but I findthis topic to be really something that I think I would never understand.It seems too complex and extremely broad for me.I am looking forward for your next post, I’ll try to get the hang of it!

  19. Amazing! This blog looks exactly like my old one! It’s on a completely different subject but it has pretty much the same layout and design. Outstanding choice of colors!

  20. Thank you a lot for sharing this with all people you really realize what you are talking approximately!Bookmarked. Please additionally discuss with my website =).We can have a link change contract among us

  21. I really like your blog.. very nice colors & theme.Did you create this website yourself or did you hire someone to doit for you? Plz answer back as I’m lookingto construct my own blog and would like to find out where u got this from.cheers

  22. Thanks for the auspicious writeup. It in reality was once a enjoymentaccount it. Look advanced to far brought agreeable from you!However, how can we be in contact?

  23. Currently it appears like Movable Type is
    the best blogging platform available right now. (from what I’ve read) Is that what you’re using on your blog?

  24. Some genuinely excellent information, Gladiola I noticed this. “War does not determine who is right – only who is left.” by Bertrand Russell.

  25. Pingback: URL
  26. Hi there! I could have sworn I’ve visited this blog before but after looking at many of the posts I realized it’s new to me.
    Regardless, I’m definitely happy I came across it and I’ll be bookmarking it and checking back often!

  27. Somebody necessarily help to make seriously articles I’d state.That is the first time I frequented your website page and so far?I amazed with the research you made to make this particular put up incredible.Magnificent task!

  28. Thanks for a marvelous posting! I truly enjoyed reading it, you may be a great author.I will be sureto bookmark your blog and will often come back down the road.I want to encourage yourself to continue your great writing,have a nice weekend!

  29. Hi! This post could not be written any better! Reading through this post reminds me of my previous room mate! He always kept talking about this. I will forward this article to him. Pretty sure he will have a good read. Thank you for sharing!

  30. Thanks for a marvelous posting! I actually enjoyed reading it,you could be a great author. I will be sure to bookmark your blog and will comeback very soon. I want to encourage you to continue your great posts, have a nice day!

  31. Thank you, I’ve recently been searching for info about this subject for a while and yours is the greatest I’ve came upon so far. However, what about the bottom line? Are you positive in regards to the supply?

  32. Hello, Neat post. There’s a problem with your website in web explorer, may check this… IE still is the market leader and a large element of people will leave out your excellent writing because of this problem.

  33. Hi! I just wanted to ask if you ever have any problems with hackers? My last blog (wordpress) was hacked and I ended up losing several weeks of hard work due to no back up. Do you have any solutions to prevent hackers?

  34. Hiya very cool site!! Man .. Excellent .. Wonderful .. I’ll bookmark your web site and take the feeds additionally…I am glad to seek out so many helpful info right here within the submit, we want work out extra techniques in this regard, thank you for sharing.

  35. I got what you mean , appreciate it for putting up.Woh I am pleased to find this website through google. “Those who corrupt the public mind are just as evil as those who steal from the public.” by Theodor Wiesengrund Adorno.

  36. I’ll immediately take hold of your rss as I can not in findingyour email subscription link or newsletter service. Do you have any?Kindly allow me recognise in order that I maysubscribe. Thanks.

  37. ปัจจุบันนี้ผู้คนต่างมองหาหนทางการสร้างรายได้ที่ลงทุนน้อย UFABET คาสิโนออนไลน์ได้เก็บทุกเกมออนไลน์ที่ท่านพอใจไม่ว่าจะเป็นบาคาร่า พนันบอล สล็อต ยิงปลา รวมถึงเกมใหม่ๆที่พึ่งเปิดตัวไปสู่วงการเกมออนไลน์ UFABET จ่ายจริง จ่ายไว ไม่มีขั้นต่ะ

  38. I don’t even know the way I finished up right here, however I believed this publish was once good. I don’t recognize who you’re but definitely you’re going to a well-known blogger if you aren’t already. Cheers!

  39. fantástico este conteúdo. Gostei muito. Aproveitem e vejam este conteúdo. informações, novidades e muito mais. Não deixem de acessar para saber mais. Obrigado a todos e até a próxima. 🙂

  40. I blog quite often and I seriously thank you for your content. This great article has truly peaked my interest. I am going to book mark your blog and keep checking for new details about once a week. I subscribed to your Feed as well.

  41. Hey, you used to write magnificent, but the last few posts have been kinda boring… I miss your tremendous writings. Past few posts are just a little out of track! come on!

  42. สาวกผี สาวกหงส์ สาวกสิงห์ สาวกเรือ สาวกไก่ สาวกสุนัขจิ้งจอก ไม่ว่าคุณจะเป็นสาวกไหนก็ตาม คาสิโนออนไลน์ ขอเป็นส่วนหนึ่งสำหรับในการเปลี่ยนสิ่งที่คุณถูกอกถูกใจเป็นรายได้ ด้วยการยกคาสิโนมาไว้ให้แด่คุณแทงบอลออนไลน์ได้อย่างง่ายๆกันเลยขอรับ

  43. Hey there! This is my first visit to your blog!We are a group of volunteers and starting a new initiative in a community in the sameniche. Your blog provided us beneficial information to workon. You have done a marvellous job!

  44. It’s actually a nice and helpful piece of info. I’m glad that you just shared this useful info with us. Please stay us up to date like this. Thank you for sharing.

  45. Tip! It may takje a before a bdand new concrete floor is totally dry. To get a laminate, the humidity should never exceed 3 . Do you really doubt? Rent a hygrometer along with a larger rental tools.

  46. Aw, this was a very nice post. In concept I would like to put in writing like this additionally – taking time and precise effort to make a very good article… however what can I say… I procrastinate alot and certainly not seem to get something done.

  47. naturally like your website however you have to check the spelling on quite a few of your posts. Many of them are rife with spelling problems and I find it very bothersome to inform the truth nevertheless I will surely come back again.

  48. I was recommended this blog by way of my cousin. I am now notpositive whether this put up is written by him as no oneelse understand such detailed approximately mytrouble. You are amazing! Thanks!

  49. It is really a great and useful piece of information. I’m glad that you simply shared thisuseful information with us. Please stay us up to datelike this. Thank you for sharing.

  50. A fascinating discussion is worth comment. I do think that you ought to publish more on this subject, it may not be a taboo subject but typically people don’t talk about such topics. To the next! Many thanks!!

  51. It’s nearly impossible to find knowledgeable people in this particular subject, however, you seem like you know what you’re talking about! Thanks

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>