Modifications

Sauter à la navigation Sauter à la recherche
3 884 octets ajoutés ,  11 février 2013 à 20:34
aucun résumé de modification
Ligne 2 : Ligne 2 :     
{{traduction}}
 
{{traduction}}
 +
 +
== Sommaire ==
 +
If you're interested in writing your own code, the easy way is to start with the examples in the code repository (the .py files starting with 'ex_'), but the following information may be helpful as well.
 +
 +
== Adafruit_LEDBackpack ==
 +
All of the low-level IO and I2C access is passed through A'''dafruit_LEDBackpack.py''', which is used by all of the other classes and examples in the library.  This file implements a class named '''LEDBackpack''', which has the following functions:
 +
 +
=== setBrightness ===
 +
setBrightness(brightness)
 +
 +
Sets the display brightness with a value between 0 and 15
 +
 +
=== setBlinkRate ===
 +
setBlinkRate(blinkRate)
 +
 +
Sets the optional blink rate for the display, with one of the following values for blinkRate
 +
   
 +
* 0 = No Blinking
 +
* 1 = Blink at 2Hz
 +
* 2 = Blink at 1Hz
 +
* 3 = Blink at 1/2 Hz
 +
 +
=== setBufferRow ===
 +
setBufferRow(row, value)
 +
 +
Updates a single row of data.  The HT16K33 contains an internal memory of 8 rows, with each row having 16 bits of data.  Each row generally corresponds to one character on a 7-segment display or one row of pixels on an 8x8 display.
 +
 +
=== getBuffer ===
 +
getBuffer()
 +
   
 +
Returns a list of 8 16-bit values representing the current state of the internal buffer, which can be used to update the display without affecting the rest of the content.
 +
 +
=== clear ===
 +
clear()
 +
 +
Clears the contents of the entire buffer
 +
 +
== Adafruit_7Segment ==
 +
The 7-Segment library is encapsulated in the file '''Adafruit_7Segment.py''', and implements a class named '''SevenSegment''' (since class names can't start with a digit).  It instantiates and instance of '''Adafruit_LEDBackpack''' internally, and you normally won't need to use the lower level class directly.  It implements the following functions:
 +
 +
=== writeDigitRaw ===
 +
writeDigitRaw(charNumber, value)
 +
 +
This will raw a raw 16-bit value to the specified charNumber, which corresponds to a single row in the HT16K33, and one character in the 4x7-segment displays.  (Note: row 2 is the colon on most 4 character displays).  You can use this to display custom characters that aren't supported natively by the current library.
 +
 +
=== writeDigit ===
 +
writeDigit(charNumber, value, dot=False)
 +
 +
Writes a single decimal (0..9) or hexadecimal (0..9 and A..F) character to the display, with charNumber being the character to update, and value being the digit.  You can set a third optional argument, dot, to True to set the decimal place after each character.
 +
 +
=== setColon ===
 +
setColon(state)
 +
 +
You can pass either True of False to this function to enable or disable the colon that is usually connected to row 2 of the HT16K33.
 +
 +
 +
== Adafruit_8x8.py ==
 +
The '''Adafruit_8x8.py''' file implements a class names '''EightByEight''' that can be used to drive 8x8 pixel square LED blocks.  It contains the following functions:
 +
 +
=== writeRowRaw ===
 +
writeRowRaw(charNumber, value)
 +
 +
This will update an entire row of data with the specified 16-bit value (though normally only the last 8-bits are used on one-color 8x8 displays.  This is faster than setting individual pixels.
 +
 +
=== setPixel ===
 +
setPixel(x, y, color)
 +
 +
This function will update a single pixel within the relevant X/Y space of the display.  Please keep in mind that lists in Python are zero-based, meaning to sets pixels 1..8 in each direction you actually use the values 0..7, so the following will enable the pixel 3 over and 5 down:
 +
 +
<nowiki>grid = EightByEight(address=0x70)
 +
grid.setPixel(2, 4)</niwiki>
 +
 +
== Exemples ===
 +
If you need a bit of help, simply looking at the provided example python code:
 +
 +
* '''ex_7segment_clock.py''': Displays the current time on a 4*7-segment display, changing the state of the colon every second
 +
* '''ex_8x8_pixels.py''': Constantly updates every pixel on an 8x8 display, one pixel at a time.
 +
 +
You can run these examples with the following code:
 +
 +
<nowiki>sudo python ex_8x8_pixels.py</nowiki>
    
{{Rasp-Hack-Led-Backpack-TRAILER}}
 
{{Rasp-Hack-Led-Backpack-TRAILER}}
29 836

modifications

Menu de navigation