pylibftdi / pylibftdi / examples / led_flash.py

Ben Bass 09339ba 


Ben Bass b971b80 

Ben Bass 9aed513 
Ben Bass 09339ba 



Ben Bass e7b00ab 
Ben Bass c87d589 
Ben Bass 09339ba 
Ben Bass fed55e4 
Ben Bass 09339ba 



Ben Bass c87d589 
Ben Bass 09339ba 
Ben Bass fed55e4 
Ben Bass 09339ba 

Ben Bass e7b00ab 








Ben Bass 09339ba 
Ben Bass e7b00ab 
"""
Flash an LED connected via a FTDI UM232R/245R module using pylibftdi

Optionally supply a flash rate (in Hz, default 1) as an argument

Copyright (c) 2010-2012 Ben Bass <benbass@codedstructure.net>
All rights reserved.
"""

import time
import sys
from pylibftdi import BitBangDevice


def flash_forever(rate):
    "toggle bit zero at rate Hz"
    # put an LED with 1Kohm or similar series resistor
    # on D0 pin
    with BitBangDevice() as bb:
        while True:
            time.sleep(1.0 / (2 * rate))
            bb.port ^= 1


def main():
    if len(sys.argv) > 1:
        rate = float(sys.argv[1])
        flash_forever(rate)
    else:
        flash_forever(1)


if __name__ == '__main__':
    main()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.