Page 1 of 1

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!

Pac Man Code
Clear all

[Solved] Pac Man Code

4 Posts
2 Users
Active Member
Joined: 3 years ago
Posts: 4
Topic starter  

Ok so i am running hyperion on my tv looks amazing. Upon looking thru the effects i found this pac man effect. Now here's my question i've tried many times to port the code over to work with ardunio but i have had no luck so i was wondering if one could help out it would be greatly appreciated.

import hyperion, time
from random import randint

#get args
rotationTime = float(hyperion.args.get('rotationTime', 4))
marginPos    = float(hyperion.args.get('margin-pos', 2))

# define pacman
pacman = bytearray((255, 255, 0))

# define ghosts
redGuy  = bytearray((255, 0, 0))
pinkGuy = bytearray((255, 184, 255))
blueGuy = bytearray((0, 255, 255))
slowGuy = bytearray((255, 184, 81))

light = bytearray((255, 184, 174))
background = bytearray((0, 0, 0))

posPac    = 1
diffPac   = 6*marginPos
diffGuys  = 3*marginPos
sleepTime = max(0.02,rotationTime/hyperion.ledCount)

posPinkGuy = posPac + diffPac
posBlueGuy = posPinkGuy + diffGuys
posSlowGuy = posBlueGuy + diffGuys
posRedGuy = posSlowGuy + diffGuys

# initialize the led data
ledDataEscape = bytearray()
for i in range(hyperion.ledCount):
	if i == 1:
		ledDataEscape += pacman
	elif i == posPinkGuy:
		ledDataEscape += pinkGuy
	elif i == posBlueGuy:
		ledDataEscape += blueGuy
	elif i == posSlowGuy:
		ledDataEscape += slowGuy
	elif i == posRedGuy:
		ledDataEscape += redGuy
		ledDataEscape += background

ledDataChase = bytearray()
for i in range(hyperion.ledCount):
	if i == 1:
		ledDataChase += pacman
	elif i in [posPinkGuy, posBlueGuy, posSlowGuy, posRedGuy]:
		ledDataChase += bytearray((33, 33, 255))
		ledDataChase += background

# increment = 3, because LED-Color is defined by 3 Bytes
increment = 3

def shiftLED(ledData, increment, limit, lightPos=None):
	state = 0
	while state < limit and not hyperion.abort():
		ledData = ledData[increment:] + ledData[:increment]

		if (lightPos):
			tmp = ledData[lightPos]
			ledData[lightPos] = light


		if (lightPos):
			ledData[lightPos] = tmp

		state += 1

# start the write data loop
while not hyperion.abort():

	# escape mode
	ledData = ledDataEscape
	shiftLED(ledData, increment, hyperion.ledCount)

	random = randint(10,hyperion.ledCount)

	# escape mode + power pellet
	s = slice(3*random, 3*random+3)
	shiftLED(ledData, increment, hyperion.ledCount - random, s)

	# chase mode
	shift   = 3*(hyperion.ledCount - random)
	ledData = ledDataChase[shift:]+ledDataChase[:shift]
	shiftLED(ledData, -increment, 2*hyperion.ledCount-random)

Famed Member Admin
Joined: 11 years ago
Posts: 2703

Hi BeginnerLED 😊 

(cool username!)

This looks like Python code (I could be wrong), and I'm not 100% sure what this effect should look like.
Converting Python to C isn't always as straight forward as one would hope, so it may be easier to create code from scratch.
That is ... if we want it converted to C, since I see that it uses the Hyperion library as well.
In other words: are you looking for Arduino code or Hyperion code that runs on whatever device is running Hyperion?

Active Member
Joined: 3 years ago
Posts: 4
Topic starter  

Arduino code i pulled it from the Hyperion library. The code is Pac man so the ghost chase Pac man then a random dot pops up and Pac man chases them

Famed Member Admin
Joined: 11 years ago
Posts: 2703

Unfortunately, the code you listed is not Arduino code, so I'm unable to do anything with it 😞 

I did find you code here and it suggests that this must be ran on the device that is running Hyperion (not the Arduino).
From what I'm reading there, these are installed by default and can be controlled with the web-interface of your Hyperion setup.
This Wiki page may be helpful. You'll see in the screenshot that there is an "Effects" option ... I copied the screenshot here and added an indicator where to find these settings.

From what I understand is that you need to use a webbrowser (on your PC) and go to the configuration screen, for example: (the IP address of the device that is running Hyperion).