Here's the new main routine adapted from the original code as referenced in the post on LCD a couple of days ago:
def main():
# Main program block
api = twitter.Api(consumer_key='xxx',
consumer_secret='xxx',
access_token_key='xxx',
access_token_secret='xxx')
GPIO.setmode(GPIO.BCM) # Use BCM GPIO numbers
GPIO.setup(LCD_E, GPIO.OUT) # E
GPIO.setup(LCD_RS, GPIO.OUT) # RS
GPIO.setup(LCD_D4, GPIO.OUT) # DB4
GPIO.setup(LCD_D5, GPIO.OUT) # DB5
GPIO.setup(LCD_D6, GPIO.OUT) # DB6
GPIO.setup(LCD_D7, GPIO.OUT) # DB7
GPIO.setup(LED_ON, GPIO.OUT) # Backlight enable
# Initialise display
lcd_init()
GPIO.output(LED_ON, True)
while(True):
nowTime = time.time()
loopTime = nowTime + 30
print 'loop'
results = api.GetMentions()
msg1 = ' from @' + results[0].user.screen_name + ' '
msg2 = ' ' + results[0].text + ' '
msg1Idx = 0
msg2Idx = 0
while(time.time() < loopTime):
view1 = msg1[msg1Idx:msg1Idx + 16]
if(msg1Idx + 16 > len(msg1)):
msg1Idx = 0
view2 = msg2[msg2Idx:msg2Idx + 16]
if(msg2Idx + 16 > len(msg2)):
msg2Idx = 0
lcd_byte(LCD_LINE_1, LCD_CMD)
lcd_string(view1, 1)
lcd_byte(LCD_LINE_2, LCD_CMD)
lcd_string(view2, 1)
time.sleep(0.2)
msg1Idx += 1
msg2Idx += 1
No comments:
Post a Comment