Пример #1
0
def main():

    # now just write the code you would use in a real Raspberry Pi

    from gpiozero import LED, Button
    from time import sleep
    from Adafruit_CharLCD import Adafruit_CharLCD

    lcd = Adafruit_CharLCD(2, 3, 4, 5, 6, 7, 16, 2)

    global count
    count = 0

    def show_next_characters():
        global count

        print(f"Showing characters from code {count} to {count+31}")

        string = ""
        for i in range(0, 32):
            string += chr(count)
            if i == 15:
                string += "\n"
            count += 1

        lcd.clear()
        lcd.message(string)

    button = Button(11)
    button.when_pressed = show_next_characters

    show_next_characters()

    while True:
        sleep(0.1)
Пример #2
0
def print_to_LCDScreen (message):
    try:
        lcd = Adafruit_CharLCD()
        lcd.begin(16,2)
        for x in range(0, 16):
            for y in range(0, 2):
                lcd.setCursor(x, y)
                lcd.message('>')
                time.sleep(.025)
        lcd.noDisplay()
        lcd.clear()
        lcd.message(str(message))
        for x in range(0, 16):
            lcd.DisplayLeft()
        lcd.display()
        for x in range(0, 16):
            lcd.scrollDisplayRight()
            time.sleep(.05)
        # lcd.noDisplay()
        # lcd.display()
        # lcd.blink()
        # lcd.noCursor()
        # lcd.clear()
        # lcd.noBlink()
        # lcd.begin(16, 2)
        # lcd.setCursor(7, 0)
        # lcd.message('123')
        # lcd.message('x')
        # lcd.clear()
        return 'ok'
    except Exception,e:
        return e
Пример #3
0
    def __init__(self, queues):
        ''' Initialize the LCD display '''
        Process.__init__(self, name="LCD")

        self.inQueue = queues[0]  # to read from
        self.outQueue = queues[1]  # to write to

        # LCD PINS
        self.PIN_RS = 26  # RS pin of LCD
        self.PIN_E = 19  # enable pin of LCD
        self.PIN_DB = [13, 6, 5, 11]  # data pins for LCD
        self.LCD_COL_SIZE = 2  # number of charactes available vertically on LCD
        self.LCD_ROW_SIZE = 16  # the number of characters available horizontally on LCD
        self.PIN_BLT = None

        self.DEF_MSG_LEN = 10  # the default space allocated for displaying a message on LCD

        self.PIN_LCD_BACKLIGHT = 20  # backlight pin for LCD
        # the Adafruit LCD object
        self.lcd = Adafruit_CharLCD(self.PIN_RS, self.PIN_E, self.PIN_DB[0],
                                    self.PIN_DB[1], self.PIN_DB[2],
                                    self.PIN_DB[3], self.LCD_COL_SIZE,
                                    self.LCD_ROW_SIZE)

        self.curr_screen = []

        # fill current screen with empty
        for i in range(self.LCD_COL_SIZE * self.LCD_ROW_SIZE):
            self.curr_screen.append(" ")

        # turn on the display
        if (self.PIN_BLT != None):
            GPIO.setmode(GPIO.BCM)
            GPIO.setup(PIN_BLT, GPIO.OUT)
            GPIO.output(self.PIN_BLT, 1)
Пример #4
0
def print_to_lcd():
    """ Print values to a 2x16 LCD display if it is provided with connections described """
    lcd = Adafruit_CharLCD(rs=26,
                           en=19,
                           d4=13,
                           d5=6,
                           d6=5,
                           d7=21,
                           cols=16,
                           lines=2)
    lcd.clear()
    lcd.set_cursor(0, 0)
    lcd.message("DHT22 Program")
    lcd.set_cursor(0, 1)
    lcd.message("Waiting...")
    sleep(2)
    try:
        while True:
            hum, temp = get_values()
            lcd.clear()
            lcd.set_cursor(0, 0)
            lcd.message("Temp: {0:.2f} C".format(temp))
            lcd.set_cursor(0, 1)
            lcd.message("Humi: {0:.2f} %".format(hum))
            sleep(5)
    except KeyboardInterrupt:
        print('Exiting...')
        lcd.clear()
        lcd.set_cursor(0, 0)
        lcd.message("OFFLINE")
Пример #5
0
    def __init__(self):
        # Need a state set for this launcher.
        self.menu = ["Remote Control"]
        self.menu += ["Three Point Turn"]
        self.menu += ["Straight Line Speed"]
        self.menu += ["Line Following"]
        self.menu += ["Proximity"]
        self.menu += ["Quit Challenge"]
        self.menu += ["Power Off Pi"]

        self.menu_quit_challenge = 3

        # default menu item is remote control
        self.menu_state = 0
        self.menu_button_pressed = False
        self.drive = None
        self.wiimote = None
        # Current Challenge
        self.challenge = None
        self.challenge_name = ""

        GPIO.setwarnings(False)
        self.GPIO = GPIO

        # LCD Display
        self.lcd = Adafruit_CharLCD(pin_rs=25,
                                    pin_e=24,
                                    pins_db=[23, 17, 27, 22],
                                    GPIO=self.GPIO)
        self.lcd.begin(16, 1)
        self.lcd.clear()
        self.lcd.message('Initiating...')
        self.lcd_loop_skip = 5
        # Shutting down status
        self.shutting_down = False
Пример #6
0
def configura_Rpi():
    prints("configura_Rpi")
    global isRasp, lcd, GPIO
    global BOTAO_ESQUERDA, BOTAO_DIREITA, BOTAO_ENTER, BOTAO_ESC
    isRasp = True
    '''
    Botoes conectados nos pinos:
    BCM 4 = BOARD pin 7
    BCM 17 = BOARD pin 11
    BCM 21 = BOARD pin 13
    BCM 22 = BOARD pin 15
    '''
    BOTAO_ESQUERDA = 21
    BOTAO_DIREITA = 17
    BOTAO_ENTER = 4
    BOTAO_ESC = 22

    try:
        # raspberry pi
        import RPi.GPIO as GPIO
        GPIO.setwarnings(False)
        GPIO.setmode(GPIO.BCM)
        # LCD
        from Adafruit_CharLCD import Adafruit_CharLCD
        lcd = Adafruit_CharLCD()
        lcd.begin(16, 2)
        # I/O botoes
        GPIO.setup(BOTAO_ESQUERDA, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
        GPIO.setup(BOTAO_DIREITA, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
        GPIO.setup(BOTAO_ENTER, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
        GPIO.setup(BOTAO_ESC, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
    except RuntimeError:  # caso o programa na esteja sendo executado em um RPi
        isRasp = False
def programa():

    # importação de bibliotecas
    from gpiozero import LED
    from gpiozero import Button
    from time import sleep

    # definição de funções
    def apertaELiga():
        led.toggle()
        return

    def piscaQuatro():
        led2.blink(n=4)
        return

    def piscaContinuamente():
        led3.blink(on_time=1, off_time=3.0)

        return

    def Noaperto():
        global count
        count = count + 1
        lcd.clear()
        lcd.message(str(count))
        piscaQuatro()
        return

    def mantemAceso():
        led5.on()
        return

    # criação de componentes
    led = LED(21)
    led2 = LED(22)
    led3 = LED(23)
    led5 = LED(25)
    button = Button(11)
    button2 = Button(12)
    button3 = Button(13)

    lcd = Adafruit_CharLCD(2, 3, 4, 5, 6, 7, 16, 2)

    global count
    count = 0

    button.when_pressed = apertaELiga
    button2.when_pressed = Noaperto

    piscaContinuamente()

    # loop infinito
    while True:
        if (led3.is_lit and button3.is_pressed):
            mantemAceso()
        else:
            led5.off()
        sleep(0.2)
Пример #8
0
 def __init__(self):
     logging.info('Create LcdManager instance')
     self.running = False
     self.line1 = ''
     self.line2 = ''
     self.screen = Adafruit_CharLCD()
     self.spinner_state = 0
     return
Пример #9
0
def printLCD(string1, string2):
    '''Prints string1 and string2 onto a 16x2 character LCD.'''
    lcd = Adafruit_CharLCD()
    lcd.begin(16, 1)
    lcd.clear()
    sleep(0.5)
    lcd.message(string1 + "\n")
    lcd.message(string2)
Пример #10
0
def init(bus=1, address=0x20, gpio_count=8):
    # Create MCP230xx GPIO adapter.
    mcp = MCP230XX_GPIO(bus, address, gpio_count)

    # Create LCD, passing in MCP GPIO adapter.
    lcd = Adafruit_CharLCD(pin_rs=1, pin_e=2, pins_db=[3, 4, 5, 6], GPIO=mcp)

    lcd.clear()
    return lcd
 def lcd_clear(self, topic, payload):
     """
     This method writes to the LCD
     """
     lcd = Adafruit_CharLCD(rs=26, en=19,
                    d4=13, d5=6, d6=5, d7=11,
                    cols=16, lines=2)
     lcd.clear()
     print("CLEARED")
Пример #12
0
def dumpLCD():
    lcd = Adafruit_CharLCD()
    lcd.begin(20,4)
    lcd.clear()
    lcd.setCursor(0,0)
    lcd.message("Yay!  Treats!")
    lcd.setCursor(0,1)
    lcd.message(" ")
    lcd.setCursor(0,3)
    lcd.message("Thank you!")
Пример #13
0
def homescreen():
    lcd = Adafruit_CharLCD()
    lcd.begin(20,4)
    lcd.clear()
    lcd.setCursor(0,0)
    lcd.message("Judd Treat Machine!")
    lcd.setCursor(0,1)
    lcd.message("Awaiting Emails!")
    lcd.setCursor(0,3)
    lcd.message("Hurry up!")
Пример #14
0
def init():
    #lcd = Adafruit_CharLCD(rs=26, en=19, d4=13, d5=8, d6=5, d7=11, cols=16, lines=2)
    lcd = Adafruit_CharLCD(rs=7,
                           en=10,
                           d4=22,
                           d5=14,
                           d6=8,
                           d7=17,
                           cols=16,
                           lines=2)
    return lcd
Пример #15
0
def print_on_display(message):
    lcd = Adafruit_CharLCD(rs=26,
                           en=19,
                           d4=13,
                           d5=6,
                           d6=5,
                           d7=11,
                           cols=16,
                           lines=2)

    lcd.clear()
    lcd.message(message)
Пример #16
0
    def __init__(self, **kwargs):
        # Create MCP230xx GPIO adapter.
        mcp = MCP230XX_GPIO(CONF.lcd.bus, CONF.lcd.address,
                            CONF.lcd.gpio_count)

        # Create LCD, passing in MCP GPIO adapter.
        self._lcd = Adafruit_CharLCD(pin_rs=1,
                                     pin_e=2,
                                     pins_db=[3, 4, 5, 6],
                                     GPIO=mcp)

        self._lcd.clear()
Пример #17
0
    def __init__(self, init=True):
        # Create MCP230xx GPIO adapter.
        mcp = MCP230XX_GPIO(self.bus, self.address, self.gpio_count)

        # Create LCD, passing in MCP GPIO adapter.
        self.lcd = Adafruit_CharLCD(pin_rs=1,
                                    pin_e=2,
                                    pin_bl=7,
                                    pins_db=[3, 4, 5, 6],
                                    GPIO=mcp)
        if init:
            self.initialisation()
Пример #18
0
def main(USERNAME, PASSWORD, SENSOR_ID):

    lcd = Adafruit_CharLCD()
    lcd.clear()

    sessionToken, objectID = LoginUser(USERNAME, PASSWORD)

    pubnub = Pubnub(publish_key="pub-c-e6b9a1fd-eed2-441a-8622-a3ef7cc5853a",
                    subscribe_key="sub-c-7e14a542-b148-11e4-9beb-02ee2ddab7fe")

    channel = SENSOR_ID

    def _callback(message, channel):
        print("Message received from channel: ", message)
        data = {'status': None, 'targetTemperature': None}
        if message['airconStatus']:
            if message['airconStatus'] == 'on':
                print "Lets turn on air con now"
                lcd.clear()
                lcd.message("Aircon On!")
                logging.warning("Lets turn on air con now")
            else:
                print "lets turn off aircon now"
                lcd.clear()
                lcd.message("Aircon Off!\n  Have a good day!")
                logging.warning("Lets turn off air con now")
            data['status'] = message['airconStatus']
        if message['targetTemperature']:
            print "Lets turn aircon to : ", message['targetTemperature']

            lcd.clear()
            lcd.message("Setting temperature\n" +
                        "Temp={0:0.1f}*C".format(message['targetTemperature']))

            logging.warning("Lets turn aircon to : " +
                            str(message['targetTemperature']))
            data['targetTemperature'] = message['targetTemperature']

        if message[
                'switchOffLCD']:  #note that this might happen a few times because current logic is if last activity was more than 3 mins ago, we swtich off
            print "Lets switch off LCD"
            lcd.clear()
            logging.warning("switching off LCD")

        needToReLogin = SendDataToParse(data, objectID, sessionToken,
                                        SENSOR_ID)

    def _error(message):
        print("Error: ", message)
        logging.warning("Error: ", message)

    pubnub.subscribe(channel, callback=_callback, error=_error)
Пример #19
0
def main():
    
    # now just write the code you would use in a real Raspberry Pi
    
    from Adafruit_CharLCD import Adafruit_CharLCD
    from gpiozero import Buzzer, LED, PWMLED, Button, DistanceSensor, LightSensor, MotionSensor
    from lirc import init, nextcode
    from py_irsend.irsend import send_once
    from time import sleep
    
    def show_sensor_values():
        lcd.clear()
        lcd.message(
            "Distance: %.2fm\nLight: %d%%" % (distance_sensor.distance, light_sensor.value * 100)
        )
        
    def send_infrared():
        send_once("TV", ["KEY_4", "KEY_2", "KEY_OK"])
    
    lcd = Adafruit_CharLCD(2, 3, 4, 5, 6, 7, 16, 2)
    buzzer = Buzzer(16)
    led1 = LED(21)
    led2 = LED(22)
    led3 = LED(23)
    led4 = LED(24)
    led5 = PWMLED(25)
    led5.pulse()
    button1 = Button(11)
    button2 = Button(12)
    button3 = Button(13)
    button4 = Button(14)
    button1.when_pressed = led1.toggle
    button2.when_pressed = buzzer.on
    button2.when_released = buzzer.off
    button3.when_pressed = show_sensor_values
    button4.when_pressed = send_infrared
    distance_sensor = DistanceSensor(trigger=17, echo=18)
    light_sensor = LightSensor(8)
    motion_sensor = MotionSensor(27)
    motion_sensor.when_motion = led2.on
    motion_sensor.when_no_motion = led2.off
    
    init("default")
    
    while True:
        code = nextcode()
        if code != []:
            key = code[0]
            lcd.clear()
            lcd.message(key + "\nwas pressed!")
            
        sleep(0.2)
    def lcd_write(self, topic, payload):
        """
        This method writes to the LCD
        """
        print(payload['value'])
        print(type(payload['value']))

        lcd = Adafruit_CharLCD(rs=26, en=19,
                       d4=13, d5=6, d6=5, d7=11,
                       cols=16, lines=2)
        lcd.clear()

        text = str(payload['value'])
        lcd.message(text)
Пример #21
0
    def __init__(self):
        # Configuration
        self.pins_T0 = 3  # chip select pin for 1st thermocouple
        self.pins_T1 = 5  # chip select pin for 2nd thermocouple
        self.pins_out = 11  # output pin
        self.pins_clock = 7  # clock pin
        self.pins_relay = 24  # relay switch pin

        self.plot_avg = 5  # number of temp readings to be averaged

        self.control_time = 0  # initialize control time
        self.control_delay = 35  # control delay in second
        self.control_tolerance = 2  # tolerance

        self.alert_delay = 60  # alert delay in seconds
        self.alert_time = 0  # initialize alert time
        self.alert_email = '*****@*****.**'  # Send message to email/smtp

        self.out_temp = 'temp.csv'  # output file name for temperature data
        self.out_control = 'control.csv'  # input file name for control parameters

        self.network_cmd0 = "ip addr show wlan0 | grep inet | awk '{print $2}' | cut -d/ -f1"
        self.network_cmd1 = "ip addr show eth0 | grep inet | awk '{print $2}' | cut -d/ -f1"
        self.network_smtp = ['*****@*****.**', '030206raspberrypi']
        self.network_tweet = "/usr/local/bin/twitter [email protected] set "

        #Initialize components:
        self.LCD = Adafruit_CharLCD()
        self.LCD.begin(16, 1)
        self.RELAY = BBQpi_relay(self.pins_relay)
        self.T0 = BBQpi_thermocouple(self.pins_T0, self.pins_out,
                                     self.pins_clock)
        self.T1 = BBQpi_thermocouple(self.pins_T1, self.pins_out,
                                     self.pins_clock)

        # Initialize output files
        if os.path.isfile(self.out_temp):
            os.remove(self.out_temp)
        self.f = open(self.out_temp, 'wb')
        self.CSV = csv.writer(self.f, delimiter=',', quoting=csv.QUOTE_MINIMAL)

        # Find the devices IP Address
        self.ipaddr = ''
        try:
            self.ipaddr = run_cmd(self.network_cmd0)
        except:
            pass
        if (self.ipaddr == ''):
            self.ipaddr = run_cmd(self.network_cmd1)
Пример #22
0
    def __init__(self):
        """ LCD Constructor """

        # Setup LCD
        self.lcd = Adafruit_CharLCD(
            rs=12,
            en=5,
            d4=6,  # Pins are being hardcoded
            d5=13,
            d6=19,
            d7=26,  # 
            cols=16,
            lines=2)  # (16x2 LCD)
        # Clear the LCD
        self.lcd.clear()
Пример #23
0
 def __init__(self, cols, rows, delay, debug=False):
     # number of columns on the character LCD (min: 16, max: 20)
     self.cols = cols
     # number of rows on the character LCD (min: 1, max: 4)
     self.rows = rows
     # duration in seconds to allow human to read LCD lines
     self.delay = delay
     # print messages to shell for debugging
     self.debug = debug
     if debug == True:
         print " cols = {0}".format(cols)
         print " rows = {0}".format(rows)
         print "delay = {0}".format(delay)
     self.lcd = Adafruit_CharLCD()
     self.lcd.begin(cols, rows)
Пример #24
0
def init():
    global lcd
    global sub
    pins = rospy.get_param('/pibot/pins/LCD1602')
    lcd = Adafruit_CharLCD(pin_rs=pins['RS'],
                           pin_e=pins['EN'],
                           pins_db=pins['DATA'],
                           GPIO=None)
    lcd.begin(16, 2)
    lcd.clear()
    lcd.write('  PiBot Loaded  \n  Hello World!  ')
    lcd.setCursor(0, 0)

    rospy.init_node('lcd1602')
    sub = rospy.Subscriber('/pibot/lcd1602', String, handler)
Пример #25
0
    def __init__(self, sortedlist, config):
        nokia_lcds = []
        #get bus pins first
        hd44780bus = config['local']['buses']['hd44780']
        nokiabus = config['local']['buses']['nokia']
        hd44780data_pins = []
        for i in range(8):
            thispin = 'LCD_D' + str(i)
            if thispin in hd44780bus:
                hd44780data_pins.append(hd44780bus[thispin])

        nokia_rst = nokiabus['LCD_RST']
        nokia_dc = nokiabus['LCD_DC']

        for ctrlid in sortedlist:
            dispdef = config['local']['controls'][ctrlid]['display']
            if dispdef['type'] == 'hd44780':
                newlcd = Adafruit_CharLCD(pin_rs=hd44780bus['LCD_RS'],
                                          pins_db=hd44780data_pins)
                newlcd.pin_e = dispdef['pin']
                GPIO.setup(newlcd.pin_e, GPIO.OUT)
                GPIO.output(newlcd.pin_e, GPIO.LOW)
                newlcd.begin(dispdef['width'], dispdef['height'])
                self.lcd[ctrlid] = newlcd
                print "Control %s is hd44780 on pin %s" % (ctrlid,
                                                           newlcd.pin_e)
            else:
                if "contrast" in dispdef:
                    contrast = int(dispdef['contrast'])
                else:
                    contrast = 0xbb
                newlcd = NokiaLCD(pin_DC=nokia_dc,
                                  pin_RST=nokia_rst,
                                  pin_SCE=dispdef['pin'],
                                  contrast=contrast)
                newlcd.width = dispdef['width']
                newlcd.height = dispdef['height']
                newlcd.display_init()
                self.lcd[ctrlid] = newlcd
                nokia_lcds.append(newlcd)
                print "Control %s is nokia on pin %s" % (ctrlid,
                                                         dispdef['pin'])
        # Do this now as it does not work in the big loop for some reason.
        if len(nokia_lcds) > 0:
            nokia_lcds[0].reset_all_displays()
            for nokia_lcd in nokia_lcds:
                nokia_lcd.display_init()
Пример #26
0
 def __init__(self, bus=None, addr=None, **kwargs):
     """
     """
     oid = kwargs.pop('oid', 'rpilcdchar.screen')
     name = kwargs.pop('name', "Screen")
     product_name = kwargs.pop('product_name', "Screen")
     product_type = kwargs.pop('product_type', "Screen")
     JNTComponent.__init__(self,
                           oid=oid,
                           bus=bus,
                           addr=addr,
                           name=name,
                           product_name=product_name,
                           product_type=product_type,
                           **kwargs)
     logger.debug("[%s] - __init__ node uuid:%s", self.__class__.__name__,
                  self.uuid)
     uuid = "message"
     self.values[uuid] = self.value_factory['action_string'](
         options=self.options,
         uuid=uuid,
         node_uuid=self.uuid,
         help='A message to print on the screen',
         label='Msg',
         default='Janitoo started',
         set_data_cb=self.set_message,
         is_writeonly=True,
         cmd_class=COMMAND_MOTOR,
         genre=0x01,
     )
     poll_value = self.values[uuid].create_poll_value(default=300)
     self.values[poll_value.uuid] = poll_value
     self.pin_lcd_rs = 27  # Note this might need to be changed to 21 for older revision Pi's.
     self.pin_lcd_en = 22
     self.pin_lcd_d4 = 25
     self.pin_lcd_d5 = 24
     self.pin_lcd_d6 = 23
     self.pin_lcd_d7 = 18
     self.pin_lcd_backlight = 4
     self.lcd_columns = 20
     self.lcd_rows = 4
     self.lcd = Adafruit_CharLCD(self.pin_lcd_rs, self.pin_lcd_en,
                                 self.pin_lcd_d4, self.pin_lcd_d5,
                                 self.pin_lcd_d6, self.pin_lcd_d7,
                                 self.lcd_columns, self.lcd_rows,
                                 self.pin_lcd_backlight)
Пример #27
0
class Logger():
    KOBUKI_BASE_MAX_CHARGE = 160
    kobuki_previous_battery_level = 1000

    lcd = Adafruit_CharLCD(rs=26,
                           en=19,
                           d4=13,
                           d5=6,
                           d6=5,
                           d7=11,
                           cols=16,
                           lines=2)

    def __init__(self):
        self.lcd.clear()
        self.lcd.message("Starting...")

        rospy.init_node("toktak_logger", anonymous=False)

        rospy.on_shutdown(self.shutdown)

        rospy.Subscriber("/mobile_base/sensors/core", SensorState,
                         self.SensorPowerEventCallback)
        rospy.spin()

    def SensorPowerEventCallback(self, msg):
        if (math.fabs(int(msg.battery) - self.kobuki_previous_battery_level) >
                2):
            battery_level = round(
                float(msg.battery) / float(self.KOBUKI_BASE_MAX_CHARGE) * 100)
            rospy.loginfo("Kobuki's battery is now: " + str(battery_level) +
                          "%")
            self.kobuki_previous_battery_level = int(msg.battery)
            self.display_lcd(battery_level)

    def display_lcd(self, msg):
        self.lcd.clear()
        self.lcd.message("Battery: " + str(msg) + "%")

    def shutdown(self):
        self.lcd.clear()
        self.lcd.message("Stop")
        rospy.loginfo("Stop")
Пример #28
0
    def __init__(self):
        '''
        Constructor
        '''

        # the next assignment connenct the raspi to the adafruit
        RSE = 21
        ENABLEIO = 20
        GPIO1 = 16
        GPIO2 = 12
        GPIO3 = 7
        GPIO4 = 8
        self.lcd = Adafruit_CharLCD(rs=RSE,
                                    en=ENABLEIO,
                                    d4=GPIO1,
                                    d5=GPIO2,
                                    d6=GPIO3,
                                    d7=GPIO4,
                                    cols=16,
                                    lines=2)
Пример #29
0
    def get_lcd_controller(self, columns, lines):
        from Adafruit_CharLCD import Adafruit_CharLCD
        lcd = Adafruit_CharLCD(
            cols=columns,
            lines=lines,
            rs=self._pin_rs,
            en=self._pin_en,
            d4=self._pin_d4,
            d5=self._pin_d5,
            d6=self._pin_d6,
            d7=self._pin_d7,
            backlight=self._pin_backlight,
            invert_polarity=False,
            enable_pwm=self._enable_pwm,
            pwm=self._get_pwm(),
        )

        # Create custom chars, since not all ROMS have the PLAY and
        # PAUSE chars or other ones the user might need
        for i, pattern in enumerate(self._custom_char_patterns):
            lcd.create_char(i, pattern)

        return lcd
Пример #30
-1
def programa():
    
    # importação de bibliotecas
    from time import sleep
    from mplayer import Player
    from gpiozero import LED
    from gpiozero import Button
    from Adafruit_CharLCD import Adafruit_CharLCD


    # definição de funções
    #player.loadfile("musica.mp3")
    #player.loadlist("lista.txt")

    def TocarEPausar():
      player.pause()
      if (player.paused):
        led.blink()
      else:
        led.on()


    def ProximaFaixa():
      player.pt_step(1)
      return

    def FaixaAnterior():
      if (player.time_pos > 2.00):
        player.time_pos = 0.00
        return
      player.pt_step(-1)
      return

    # criação de componentes
    player = Player()
    player.loadlist("playlist.txt")

    led = LED(21)
    
    lcd = Adafruit_CharLCD(2,3,4,5,6,7,16,2)

    button1 = Button(11)
    button2 = Button(12)
    button3 = Button(13)
    
    button1.when_pressed = FaixaAnterior
    button2.when_pressed = TocarEPausar
    button3.when_pressed = ProximaFaixa

    led.on()
    # loop infinito
    while True:
      metadados = player.metadata
      if metadados != None: 
        nome = player.metadata["Title"]
        lcd.clear()
        lcd.message(nome)
      sleep(0.2)