Modifications

Sauter à la navigation Sauter à la recherche
3 332 octets ajoutés ,  31 décembre 2016 à 10:44
Ligne 176 : Ligne 176 :     
That's all there is to using the '''Adafruit_CharLCD''' class!
 
That's all there is to using the '''Adafruit_CharLCD''' class!
 +
 +
== Avec un LCD RGB ==
 +
If you're using an RGB backlight LCD the '''char_lcd_rgb.py''' script will demonstrate the usage.
 +
 +
If you're using a Raspberry Pi and have wired it according to this guide, you can immediately run the script. However if you're using a BeagleBone Black or have changed the wiring, edit the script with a text editor and uncomment/change the lines at the top that define the LCD pins.
 +
 +
To execute the RGB backlight example run this command from inside the '''examples''' directory:
 +
 +
sudo python char_lcd_rgb.py
 +
 +
You should see the LCD turn on and display different backlight colors. For example:
 +
 +
{{ADFImage|Rasp-Hack-Afficheur-LCD-Python-a10.jpg}}
 +
 +
If you open the file '''char_lcd_rgb.py''' in a text editor (such as nano) I'll describe the important differences between it and the previous '''char_lcd.py''' example below.
 +
 +
<syntaxhighlight lang="python">
 +
# Example Raspberry Pi configuration:
 +
lcd_rs = 27  # Change this to pin 21 on older revision Raspberry Pi's
 +
lcd_en = 22
 +
lcd_d4 = 25
 +
lcd_d5 = 24
 +
lcd_d6 = 23
 +
lcd_d7 = 18
 +
lcd_red  = 4
 +
lcd_green = 17
 +
lcd_blue  = 7  # Pin 7 is CE1
 +
 +
# Example BeagleBone Black configuration:
 +
# lcd_rs = 'P8_8'
 +
# lcd_en = 'P8_10'
 +
# lcd_d4 = 'P8_18'
 +
# lcd_d5 = 'P8_16'
 +
# lcd_d6 = 'P8_14'
 +
# lcd_d7 = 'P8_12'
 +
# lcd_red  = 'P8_7'
 +
# lcd_green = 'P8_9'
 +
# lcd_blue  = 'P8_11'
 +
</syntaxhighlight>
 +
 +
The first important difference is the configuration of LCD pins. Notice there are now explicit pins defined for the red, green, and blue backlight LEDs.
 +
 +
<syntaxhighlight lang="python">
 +
# Initialize the LCD using the pins
 +
lcd = LCD.Adafruit_RGBCharLCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7,
 +
                              lcd_columns, lcd_rows, lcd_red, lcd_green, lcd_blue)
 +
</syntaxhighlight>
 +
 +
The next line creates an instance of the '''Adafruit_RGBCharLCD''' class using the pin configuration defined earlier.
 +
 +
The '''Adafruit_RGBCharLCD''' class inherits from the '''Adafruit_CharLCD''' class so it has all the same functionality as demonstrated in the '''char_lcd.py''' example. In addition to the basic character LCD functionality the RGB character LCD class adds some functions to set the RGB color of the backlight.
 +
 +
<syntaxhighlight lang="python">
 +
# Show some basic colors.
 +
lcd.set_color(1.0, 0.0, 0.0)
 +
lcd.clear()
 +
lcd.message('RED')
 +
time.sleep(3.0)
 +
 +
lcd.set_color(0.0, 1.0, 0.0)
 +
lcd.clear()
 +
lcd.message('GREEN')
 +
time.sleep(3.0)
 +
 +
lcd.set_color(0.0, 0.0, 1.0)
 +
lcd.clear()
 +
lcd.message('BLUE')
 +
time.sleep(3.0)
 +
 +
lcd.set_color(1.0, 1.0, 0.0)
 +
lcd.clear()
 +
lcd.message('YELLOW')
 +
time.sleep(3.0)
 +
 +
lcd.set_color(0.0, 1.0, 1.0)
 +
lcd.clear()
 +
lcd.message('CYAN')
 +
time.sleep(3.0)
 +
 +
lcd.set_color(1.0, 0.0, 1.0)
 +
lcd.clear()
 +
lcd.message('MAGENTA')
 +
time.sleep(3.0)
 +
 +
lcd.set_color(1.0, 1.0, 1.0)
 +
lcd.clear()
 +
lcd.message('WHITE')
 +
time.sleep(3.0)
 +
</syntaxhighlight>
 +
 +
The code above demonstrates each basic color by calling the {{fname|set_color}} function and passing in which red, green, and blue LEDs to enable. For example the first call to {{fname|set_color(1.0, 0.0, 0.0)}} will turn on the '''red''' LED and turn off the green and blue LED so the backlight will have a '''red''' color.
 +
 +
Notice how later lines combine multiple LEDs to get different colors, like calling {{fname|set_color(1.0, 0.0, 1.0)}} to combine '''red''' and '''blue''' LEDs for a '''magenta/violet''' color.
    
== L'exemple Horloge + IP ==
 
== L'exemple Horloge + IP ==
29 917

modifications

Menu de navigation