element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Raspberry Pi Projects
  • Products
  • Raspberry Pi
  • Raspberry Pi Projects
  • More
  • Cancel
Raspberry Pi Projects
Blog Step by Step Build Trick or Trivia Halloween Candy Dispenser #4 - LED blink test, GUI Interface
  • Blog
  • Documents
  • Events
  • Polls
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi Projects to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: cmelement14
  • Date Created: 25 Oct 2015 5:08 PM Date Created
  • Views 348 views
  • Likes 1 like
  • Comments 0 comments
  • raspberry_pi_projects
  • pumpkinpi2015
Related
Recommended

Step by Step Build Trick or Trivia Halloween Candy Dispenser #4 - LED blink test, GUI Interface

cmelement14
cmelement14
25 Oct 2015

While I am waiting for answers about starting Python interpreter in privilege mode mentioned in my previous blog Step by Step Build Trick or Trivia Halloween Candy Dispenser #3, I'd like to continue my journey. This is going to be a short blog about how I work on LED blink.

 

I wrote a small piece code LED_Blink_Test.py which blinks LED(toggling red/green LEDs every second) until I hit the enter key. It works as expected.


import RPi.GPIO as GPIO
import time
import sys
import select


GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(26, GPIO.OUT)
GPIO.setup(19, GPIO.OUT)


state = True


def toggle_leds():
  global state
  if state:
  GPIO.output(26, True)
  GPIO.output(19, False)
  state = False
  else:
  GPIO.output(26, False)
  GPIO.output(19, True)
  state = True

# endless loop until enter key is stroked, green & red LEDs alternately on/off for 1 second
while True:
  while sys.stdin in select.select([sys.stdin], [], [], 0)[0]:
  line = sys.stdin.readline()
  if line:
  GPIO.cleanup()
  exit(0)
  else:
  toggle_leds()
  time.sleep(1)

 

I used the same pins to drive LEDs as Charles Gantt used in his blog, but I didn't directly connect LEDs to those pins. The reason for it because each pin will consume more than 25mA if they are directly driven by pins. I am not very comfortable to pull such a big current from an I/O pin unless I see it's specified in its datasheet. Some kind of current limit is required. I don't have appropriate resistors to limit the current to 5 to 10mA per pin, however, the kit includes a few diodes, so I put two diodes in serie to limit the current to about 3mA. The LED isn't super bright, but definitely visible when it lights up.

 

image

 

Make sure you run Python in privilege sudo python LED_Blink_Test.py. Otherwise, you will have run-time problem.

image

To check the GUI interface, I have to comment out all GPIO related statements. Then run python TrickorTriviaQuiz.py and GUI shows up like this:



image

Stay tune for the next blog.

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube