# Displayotron-3k-hat countdown timer

**URL:** <https://forums.pimoroni.com/t/displayotron-3k-hat-countdown-timer/2910>\
**Category:** Raspberry Pi\
**Created:** [August 24, 2016, 7:43pm UTC](https://forums.pimoroni.com/t/displayotron-3k-hat-countdown-timer/2910 "2016-08-24T19:43:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![arborowen](https://avatars.discourse-cdn.com/v4/letter/a/b3f665/32.png) [@arborowen](https://forums.pimoroni.com/u/arborowen)\
**Post date:** [August 24, 2016, 7:43pm UTC](https://forums.pimoroni.com/t/displayotron-3k-hat-countdown-timer/2910/1 "2016-08-24T19:43:49Z")

</div>

Hi recently purchased a Dothat, teaching myself python partly by taking things apart and re-making them with the dothat.

I started out by making a small script to operate the dothat as a torch. This works but I then wanted to make it operate and show a countdown timer while the lights were lit.

This is what I have, it is adapted from a basic countdown script form a few google searches. It works in the IDLE using print in place of lcd.write

[Pastbin](http://pastebin.com/FXKvQCw8)

In my nativity I thought I could swap out print for lcd.write this approach works in the final “goodbye” line of code which does print to the screen but the count down does not.

Please be gentle to those of you who know what you are doing im sure this is a very simple question of improper syntax … possibly but im lost all the same.

---

<div class="post-metadata">

**Author:** ![gadgetoid](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/gadgetoid/32/13_2.png) [@gadgetoid](https://forums.pimoroni.com/u/gadgetoid)\
**Post date:** [August 24, 2016, 8:14pm UTC](https://forums.pimoroni.com/t/displayotron-3k-hat-countdown-timer/2910/2 "2016-08-24T20:14:25Z")

</div>

Try: `lcd.write(str(count))`

This should coerce the count into a string, otherwise it might be interpreted as a character index.

The characters the LCD can theoretically display are on page 5 of this datasheet: [http://www.lcd-module.de/pdf/doma/dog-m.pdf](http://www.lcd-module.de/pdf/doma/dog-m.pdf)

Characters 0 through 7 are all blank by default, so counting down 3, 2, 1 would result in… nothing at all.

Fantastically confusing little syntax niggle to come across, though! I’m not surprised it had you stumped.

---

<div class="post-metadata">

**Author:** ![arborowen](https://avatars.discourse-cdn.com/v4/letter/a/b3f665/32.png) [@arborowen](https://forums.pimoroni.com/u/arborowen)\
**Post date:** [August 25, 2016, 5:22am UTC](https://forums.pimoroni.com/t/displayotron-3k-hat-countdown-timer/2910/3 "2016-08-25T05:22:44Z")

</div>

Thanks Phil.

Well I’m glad in a way. when I get a chance today I’ll try it. with  
reference toy 321 are you saying the characters will not display ?

I’m sure I’ll have more questions once I try this. my plan is to set it up  
so I can trigger the “torch” and show a countdown from 30 on screen. simple  
stuff but so far just fiddling with these examples that come with the  
Dothat I’ve learned allot.

thanks again

---

<div class="post-metadata">

**Author:** ![gadgetoid](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/gadgetoid/32/13_2.png) [@gadgetoid](https://forums.pimoroni.com/u/gadgetoid)\
**Post date:** [August 25, 2016, 9:26am UTC](https://forums.pimoroni.com/t/displayotron-3k-hat-countdown-timer/2910/4 "2016-08-25T09:26:37Z")

</div>

The character _indexes_ 0, 1, 2, 3, 4, 5, 6 and 7 are user characters, used for custom icons or animations. By default they’re blank, so if you try something like: `lcd.write(0)` then it will display, but since it’s blank you wont be able to see it.

The actual _numbers_ 0, 1, 2, 3, 4, 5, 6 etc are at _indexes_ 48, 49, 50, 51.

So if you `lcd.write("0")` that’s the same as running `lcd.write(48)`.

You can convert between characters and their ordinals/indexes quite easily in Python, like so (this is in a Python repl):

```python
>>> ord("1")
48

```

And:

```auto
>>> chr(48)
'0'

```

These are super useful things to remember, since characters are always represented as numbers in computers.

This is also why in some examples you’ll see something like `lcd.write("Such icon!:" + chr(0)")`, this is deliberately writing out the first user character, because it contains some custom artwork.

---

<div class="post-metadata">

**Author:** ![arborowen](https://avatars.discourse-cdn.com/v4/letter/a/b3f665/32.png) [@arborowen](https://forums.pimoroni.com/u/arborowen)\
**Post date:** [August 25, 2016, 9:53am UTC](https://forums.pimoroni.com/t/displayotron-3k-hat-countdown-timer/2910/5 "2016-08-25T09:53:47Z")

</div>

Very helpful, I’ll try and remember. The count down works well and I have  
added backlight.set\_graph (1) to enable the light for 30 seconds also with  
success. I now need to wrangle with the position of text and work out how  
to make it scroll across the first line of the display and have the  
countdown of the 2nd line.

---

<div class="post-metadata">

**Author:** ![arborowen](https://avatars.discourse-cdn.com/v4/letter/a/b3f665/32.png) [@arborowen](https://forums.pimoroni.com/u/arborowen)\
**Post date:** [August 25, 2016, 11:52am UTC](https://forums.pimoroni.com/t/displayotron-3k-hat-countdown-timer/2910/6 "2016-08-25T11:52:35Z")

</div>

OK here is the finished [torch.py](http://torch.py) which included the countdown script resolved in this thread in case anyone is interested.

A strange thing occurs when choosing a different cursor position it causes the printed text to jump lines? although the combination of positions i have in tis code seem to present themselves nicley.

[torch.py](http://pastebin.com/N0szhNrQ)[quote=“arborowen, post:6, topic:2910”]  
thing  
[/quote]  
[http://sendvid.com/10bfz02s](http://sendvid.com/10bfz02s)
