Ejemplo n.º 1
0
    def __init__(self, rs, en, d4, d5, d6, d7, cols, lines, red, green, blue,
                 gpio=GPIO.get_platform_gpio(), 
                 invert_polarity=True,
                 enable_pwm=False,
                 pwm=PWM.get_platform_pwm(),
                 initial_color=(1.0, 1.0, 1.0)):
        """Initialize the LCD with RGB backlight.  RS, EN, and D4...D7 parameters 
        should be the pins connected to the LCD RS, clock enable, and data line 
        4 through 7 connections. The LCD will be used in its 4-bit mode so these 
        6 lines are the only ones required to use the LCD.  You must also pass in
        the number of columns and lines on the LCD.

        The red, green, and blue parameters define the pins which are connected
        to the appropriate backlight LEDs.  The invert_polarity parameter is a
        boolean that controls if the LEDs are on with a LOW or HIGH signal.  By
        default invert_polarity is True, i.e. the backlight LEDs are on with a
        low signal.  If you want to enable PWM on the backlight LEDs (for finer
        control of colors) and the hardware supports PWM on the provided pins,
        set enable_pwm to True.  Finally you can set an explicit initial backlight
        color with the initial_color parameter.  The default initial color is
        white (all LEDs lit).

        You can optionally pass in an explicit GPIO class,
        for example if you want to use an MCP230xx GPIO extender.  If you don't
        pass in an GPIO instance, the default GPIO for the running platform will
        be used.
        """
        super(Adafruit_RGBCharLCD, self).__init__(rs, en, d4, d5, d6, d7,
                                                  cols,
                                                  lines, 
                                                  enable_pwm=enable_pwm,
                                                  backlight=None,
                                                  invert_polarity=invert_polarity,
                                                  gpio=gpio, 
                                                  pwm=pwm)
        self._red = red
        self._green = green
        self._blue = blue
        # Setup backlight pins.
        if enable_pwm:
            # Determine initial backlight duty cycles.
            rdc, gdc, bdc = self._rgb_to_duty_cycle(initial_color)
            pwm.start(red, rdc)
            pwm.start(green, gdc)
            pwm.start(blue, bdc)
        else:
            gpio.setup(red, GPIO.OUT)
            gpio.setup(green, GPIO.OUT)
            gpio.setup(blue, GPIO.OUT)
            self._gpio.output_pins(self._rgb_to_pins(initial_color))
Ejemplo n.º 2
0
 def __init__(self,
              width,
              height,
              rst,
              dc=None,
              sclk=None,
              din=None,
              cs=None,
              gpio=None,
              spi=None,
              i2c_bus=None,
              i2c_address=SSD1306_I2C_ADDRESS,
              i2c=None):
     self._log = logging.getLogger('Adafruit_SSD1306.SSD1306Base')
     self._spi = None
     self._i2c = None
     self.width = width
     self.height = height
     self._pages = height // 8
     self._buffer = [0] * (width * self._pages)
     # Default to platform GPIO if not provided.
     self._gpio = gpio
     if self._gpio is None:
         self._gpio = GPIO.get_platform_gpio()
     # Setup reset pin.
     self._rst = rst
     if not self._rst is None:
         self._gpio.setup(self._rst, GPIO.OUT)
     # Handle hardware SPI
     #if spi is not None:
     #    self._log.debug('Using hardware SPI')
     #    self._spi = spi
     #    self._spi.set_clock_hz(8000000)
     # Handle software SPI
     #elif sclk is not None and din is not None and cs is not None:
     #    self._log.debug('Using software SPI')
     #    self._spi = SPI.BitBang(self._gpio, sclk, din, None, cs)
     # Handle hardware I2C
     elif i2c is not None:
         self._log.debug('Using hardware I2C with custom I2C provider.')
         self._i2c = i2c.get_i2c_device(i2c_address)
     else:
         self._log.debug('Using hardware I2C with platform I2C provider.')
         import I2C
         if i2c_bus is None:
             self._i2c = I2C.get_i2c_device(i2c_address)
         else:
             self._i2c = I2C.get_i2c_device(i2c_address, busnum=i2c_bus)
Ejemplo n.º 3
0
    def __init__(self, rs, en, d4, d5, d6, d7, cols, lines, backlight=None,
                    invert_polarity=True,
                    enable_pwm=False,
                    gpio=GPIO.get_platform_gpio(),
                    pwm=PWM.get_platform_pwm(),
                    initial_backlight=1.0):
        """Initialize the LCD.  RS, EN, and D4...D7 parameters should be the pins
        connected to the LCD RS, clock enable, and data line 4 through 7 connections.
        The LCD will be used in its 4-bit mode so these 6 lines are the only ones
        required to use the LCD.  You must also pass in the number of columns and
        lines on the LCD.  

        If you would like to control the backlight, pass in the pin connected to
        the backlight with the backlight parameter.  The invert_polarity boolean
        controls if the backlight is one with a LOW signal or HIGH signal.  The 
        default invert_polarity value is True, i.e. the backlight is on with a
        LOW signal.  

        You can enable PWM of the backlight pin to have finer control on the 
        brightness.  To enable PWM make sure your hardware supports PWM on the 
        provided backlight pin and set enable_pwm to True (the default is False).
        The appropriate PWM library will be used depending on the platform, but
        you can provide an explicit one with the pwm parameter.

        The initial state of the backlight is ON, but you can set it to an 
        explicit initial state with the initial_backlight parameter (0 is off,
        1 is on/full bright).

        You can optionally pass in an explicit GPIO class,
        for example if you want to use an MCP230xx GPIO extender.  If you don't
        pass in an GPIO instance, the default GPIO for the running platform will
        be used.
        """
        # Save column and line state.
        self._cols = cols
        self._lines = lines
        # Save GPIO state and pin numbers.
        self._gpio = gpio
        self._rs = rs
        self._en = en
        self._d4 = d4
        self._d5 = d5
        self._d6 = d6
        self._d7 = d7
        # Save backlight state.
        self._backlight = backlight
        self._pwm_enabled = enable_pwm
        self._pwm = pwm
        self._blpol = not invert_polarity
        # Setup all pins as outputs.
        for pin in (rs, en, d4, d5, d6, d7):
            gpio.setup(pin, GPIO.OUT)
        # Setup backlight.
        if backlight is not None:
            if enable_pwm:
                pwm.start(backlight, self._pwm_duty_cycle(initial_backlight))
            else:
                gpio.setup(backlight, GPIO.OUT)
                gpio.output(backlight, self._blpol if initial_backlight else not self._blpol)
        # Initialize the display.
        self.write8(0x33)
        self.write8(0x32)
        # Initialize display control, function, and mode registers.
        self.displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF
        self.displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_2LINE | LCD_5x8DOTS
        self.displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT
        # Write registers.
        self.write8(LCD_DISPLAYCONTROL | self.displaycontrol)
        self.write8(LCD_FUNCTIONSET | self.displayfunction)
        self.write8(LCD_ENTRYMODESET | self.displaymode)  # set the entry mode
        self.clear()
Ejemplo n.º 4
0
import os
import atexit
from time import sleep
import Image
import Adafruit_GPIO.SPI as SPI
import pygame
from pygame.locals import*

stderr = sys.stderr.write;


DC = 22
RST = 23
SPI_PORT = 0
SPI_DEVICE = 0
gpio = GPIO.get_platform_gpio()
gpio.setup(26, GPIO.IN, pull_up_down=GPIO.PUD_UP)
gpio.setup(19, GPIO.IN, pull_up_down=GPIO.PUD_UP)
gpio.setup(13, GPIO.IN, pull_up_down=GPIO.PUD_UP)
gpio.setup(21, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Switch for Bluetooth
gpio.setup(20, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Switch for Aux
gpio.setup(16, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Switch for RPi
state = 0
btaux = 0
white = (255, 255, 255)
w = 1024
h = 768
screen = pygame.display.set_mode((1024,768),pygame.FULLSCREEN)
screen.fill((white))

# Initialize display.