Help with shutting down lcd and raspberry pi from CharLCD

Moderators: adafruit_support_bill, adafruit

Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/
Locked
User avatar
matboy16
 
Posts: 51
Joined: Thu May 09, 2013 6:05 pm

Help with shutting down lcd and raspberry pi from CharLCD

Post by matboy16 »

Here is my code for a raspberry pi email alert using a raspberry pi RGB Char LCD Plate. Could someone help me to write some code to get out of the while loop, shut down the pi and the LCD with a push of a button on the Char LCD Plate?

Code: Select all

#!/usr/bin/env python

import time
import feedparser
import math

import Adafruit_CharLCD as LCD


USERNAME = ""
PASSWORD = ""

LOOP=

NEWMAIL_OFFSET = 0
MAIL_CHECK_FREQ  = 30

lcd = LCD.Adafruit_CharLCDPlate()

while True:

        newmails = int(feedparser.parse("https://" + USERNAME + ":" + PASSWORD + "@mail.google.com/gmail/feed/atom")["feed"]["fullcount"])

   if newmails > 0:

               # print "You have ", newmails, "new emails!"
                lcd.set_color(1.0, 0.0, 0.0)
                lcd.clear()
                lcd.message("You have Mail!")
                time.sleep(0.25)

        if newmails <= 0:

                #print "You Have no new mail!"
                lcd.set_color(0.0, 1.0, 0.0)
                lcd.clear()
                lcd.message("No new mail!")
                time.sleep(0.25)



        time.sleep(MAIL_CHECK_FREQ)



User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Help with shutting down lcd and raspberry pi from CharLC

Post by adafruit_support_mike »

Change the control condition for the while loop from True to a variable named keepLooping which starts as True and gets set False when you find a condition that makes you want to stop the loop:

Code: Select all

import random

keepLooping = True

while keepLooping:
	n = random.random()
	print n
	
	if ( n > 0.95 ):
		keepLooping = False

User avatar
matboy16
 
Posts: 51
Joined: Thu May 09, 2013 6:05 pm

Re: Help with shutting down lcd and raspberry pi from CharLC

Post by matboy16 »

Is their a piece of code that I can write that will stop the program, even in the middle of time.sleep function? The button press only work if the code is not inside of the time.sleep fucton. Could I make a interrupt that will shut down the entire program with a push of a button on the lcd_plate.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Help with shutting down lcd and raspberry pi from CharLC

Post by adafruit_support_rick »

Just use an inner loop in place of your sleep. Have the loop check the button. Have the loop sleep for something like 50ms, then check the button. Loop 600 times and exit, and you'll have done the same thing as sleeping for 30 seconds.

User avatar
matboy16
 
Posts: 51
Joined: Thu May 09, 2013 6:05 pm

Re: Help with shutting down lcd and raspberry pi from CharLC

Post by matboy16 »

Thanks that helps a lot, this is why I love buying things from adafruit. The costomer service is awesome. Thanks for the help, you deserve a big thank you!!!!

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Help with shutting down lcd and raspberry pi from CharLC

Post by adafruit_support_rick »

You're welcome!

Locked
Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/

Return to “Adafruit Raspberry Pi® accessories”