User avatar
frolen13
Posts: 40
Joined: Thu Aug 15, 2013 4:14 am
Location: Mauldin, SC

Blinking Text.

Tue Dec 31, 2013 4:44 am

Alright so my first project with the rpi. I made a blinking led (so advanced :P) I have my code

Code: Select all

import RPi.GPIO as GPIO
import time
def blink(pin):
        GPIO.output(pin,GPIO.HIGH)
        time.sleep(.03)
        GPIO.output(pin,GPIO.LOW)
        time.sleep(.03)
        return
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11, GPIO.OUT)
print "Blinking..."
for i in range(0,999):
        blink(11)
GPIO.cleanup()
print "Done"
I have it display the phrase "blinking..."
I want the message to actually blink at a rate of .5 times a second until the message done is displayed.
So could someone please tell me how or give me an example code that would be great!!!!!!!! :)
Last edited by frolen13 on Tue Dec 31, 2013 7:11 am, edited 1 time in total.
-Collin

User avatar
Richard-TX
Posts: 1549
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas

Re: Blinking Text.

Tue Dec 31, 2013 4:50 am

add a 0.5 second sleep?
Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip

User avatar
frolen13
Posts: 40
Joined: Thu Aug 15, 2013 4:14 am
Location: Mauldin, SC

Re: Blinking Text.

Tue Dec 31, 2013 4:56 am

Richard-TX wrote:add a 0.5 second sleep?
well the thing is I have no idea how to make the message blink.
adding a sleep would just delay the time it takes to show the message. The led will blink for a minute and so will the message "blinking" then when the blinking is completed the blinking message will stop then the message "done" will display
-Collin

User avatar
DougieLawson
Posts: 39796
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Blinking Text.

Tue Dec 31, 2013 12:01 pm

Code: Select all

#!/usr/bin/python

import sys
import time

for i in range(0,101,10):
  sys.stdout.write("\r[%3d%%]" % i)
  sys.stdout.flush()
  time.sleep(1)

sys.stdout.write("\n")
sys.stdout.flush()

for i in range(0,10):
  sys.stdout.write("\rBlinking ...")
  sys.stdout.flush()
  time.sleep(0.5)
  sys.stdout.write("\r         ...")
  sys.stdout.flush()
  time.sleep(0.5)

sys.stdout.write("\n")
sys.stdout.flush()
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All fake doctors are on my foes list.

User avatar
frolen13
Posts: 40
Joined: Thu Aug 15, 2013 4:14 am
Location: Mauldin, SC

Re: Blinking Text.

Tue Dec 31, 2013 9:01 pm

DougieLawson wrote:

Code: Select all

#!/usr/bin/python

import sys
import time

for i in range(0,101,10):
  sys.stdout.write("\r[%3d%%]" % i)
  sys.stdout.flush()
  time.sleep(1)

sys.stdout.write("\n")
sys.stdout.flush()

for i in range(0,10):
  sys.stdout.write("\rBlinking ...")
  sys.stdout.flush()
  time.sleep(0.5)
  sys.stdout.write("\r         ...")
  sys.stdout.flush()
  time.sleep(0.5)

sys.stdout.write("\n")
sys.stdout.flush()

Ok so i implemented this into my code and this is it

Code: Select all

import RPi.GPIO as GPIO
import time
import sys
def blink(pin):
        GPIO.output(pin,GPIO.HIGH)
        time.sleep(.03)
        GPIO.output(pin,GPIO.LOW)
        time.sleep(.03)
        return
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11, GPIO.OUT)
for i in range(0,101,10):
  sys.stdout.write("\r[%3d%%]" % i)
  sys.stdout.flush()
  time.sleep(1)

sys.stdout.write("\n")
sys.stdout.flush()

for i in range(0,10):
  sys.stdout.write("\rBlinking ...")
  sys.stdout.flush()
  time.sleep(0.5)
  sys.stdout.write("\r         ...")
  sys.stdout.flush()
  time.sleep(0.5)

sys.stdout.write("\n")
sys.stdout.flush()
for i in range(0,999):
        blink(11)
GPIO.cleanup()
print "Done"
then i ran it it leads up to 100% it starts blinking then freezes at "..." while the led continues to blink. im not the best with python, im learning. thanks! :D
also is there a way to remove the loading percentage.
-Collin

User avatar
DougieLawson
Posts: 39796
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Blinking Text.

Tue Dec 31, 2013 9:24 pm

Here's my version

Code: Select all

import RPi.GPIO as GPIO
import time
import sys

pin = 11
GPIO.setmode(GPIO.BOARD)
GPIO.setup(pin, GPIO.OUT)

for i in range(0,999):
    sys.stdout.write("\rBlinking ...")
    sys.stdout.flush()
    GPIO.output(pin,GPIO.HIGH)
    time.sleep(0.5)
    sys.stdout.write("\r         ...")
    sys.stdout.flush()
    GPIO.output(pin,GPIO.LOW)
    time.sleep(0.5)

sys.stdout.write("\n")
sys.stdout.flush()
print "Done"
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All fake doctors are on my foes list.

User avatar
frolen13
Posts: 40
Joined: Thu Aug 15, 2013 4:14 am
Location: Mauldin, SC

Re: Blinking Text.

Tue Dec 31, 2013 9:29 pm

DougieLawson wrote:Here's my version

Code: Select all

import RPi.GPIO as GPIO
import time
import sys

pin = 11
GPIO.setmode(GPIO.BOARD)
GPIO.setup(pin, GPIO.OUT)

for i in range(0,999):
    sys.stdout.write("\rBlinking ...")
    sys.stdout.flush()
    GPIO.output(pin,GPIO.HIGH)
    time.sleep(0.5)
    sys.stdout.write("\r         ...")
    sys.stdout.flush()
    GPIO.output(pin,GPIO.LOW)
    time.sleep(0.5)

sys.stdout.write("\n")
sys.stdout.flush()
print "Done"
The code makes the message blink for a few seconds until the led starts to blink i want the message to blink the entire time the led flashes. i want the message to stop once the led is done blinking. and finish with the message "done"
-Collin

Return to “General discussion”