11x7 LED Matrix Breakout - Binary Clock - SOLVED

Super quick update for anyone else receiving this error. By means of a serendipitous typo, simply using python instead of python3, will resolve this, and the script runs perfectly.

Greetings,
I recently became the proud owner of the 11x7 LED Matrix Breakout.
I’m having trouble with the Binary Clock example. When trying to run using python3 from a terminal, Thonny or IDLE, I receive the following error:

Traceback (most recent call last):
  File "binary-clock.py", line 161, in <module>
    main()
  File "binary-clock.py", line 154, in main
    clock = BinaryClock()
  File "binary-clock.py", line 77, in __init__
    Clock.__init__(self)
  File "binary-clock.py", line 52, in __init__
    Time.__init__(self)
  File "binary-clock.py", line 35, in __init__
    self.update()
  File "binary-clock.py", line 137, in update
    self._brightness_step()
  File "binary-clock.py", line 120, in _brightness_step
    ] for hand_position in self._intensities.keys()
  File "binary-clock.py", line 120, in <dictcomp>
    ] for hand_position in self._intensities.keys()
  File "binary-clock.py", line 119, in <listcomp>
    next(self._intensities[hand_position][hand_bit]) for hand_bit in range(self._hand_bits)
  File "binary-clock.py", line 124, in _intensity
    degrees = range(self._max_degree) + list(reversed(range(self._max_degree)))
TypeError: unsupported operand type(s) for +: 'range' and 'list'

Which is a little beyond my “L plate” python driver experience. Can anyone find the time to guide me into getting this running, please?

Thanks in advance for any gratefully received assistance. 👍

Huh, so it seems that they changed how range works between Python 2 and Python 3, which is why one gives the error but the other doesn’t. I’d take a wild guess that if you go into the example and change this line:

degrees = range(self._max_degree) + list(reversed(range(self._max_degree)))

To this:

degrees = list(range(self._max_degree)) + list(reversed(range(self._max_degree)))

Then it might work with Python 3, but who knows if there are other issues in there.

1 Like

Hi Shoe,
Thanks for the assist. Appreciated.
After making that change, I now receive the following:

>>> %Run binary-clock.py
Traceback (most recent call last):
  File "/home/pi/Pimoroni/matrix11x7/examples/binary-clock.py", line 161, in <module>
    main()
  File "/home/pi/Pimoroni/matrix11x7/examples/binary-clock.py", line 157, in main
    clock.draw()
  File "/home/pi/Pimoroni/matrix11x7/examples/binary-clock.py", line 106, in draw
    Clock.draw(self)
  File "/home/pi/Pimoroni/matrix11x7/examples/binary-clock.py", line 64, in draw
    self._hour()
  File "/home/pi/Pimoroni/matrix11x7/examples/binary-clock.py", line 93, in _hour
    self.hour())
  File "/home/pi/Pimoroni/matrix11x7/examples/binary-clock.py", line 87, in _draw_hand
    self._draw_binary(x_left, value / 10)
  File "/home/pi/Pimoroni/matrix11x7/examples/binary-clock.py", line 84, in _draw_binary
    1 if value & (1 << y) > 0 else self._brightness[x][y])
TypeError: unsupported operand type(s) for &: 'float' and 'int'
>>> 

I’m going to write it off, as deprecated.
Thanks again for your help.