Sunday, March 20, 2016

Raspberry Pi Explorer Hat Pro Tutorial: Mod with 3 different Potentiometers for controlling Minecraft Virtual Bars: Part Two


This final remix of Pimoroni's Explorer Hat pro was definitely a challenge that forced me to do some major problem solving. Firstly, I found that the blue mini breadboard that comes with the Explorer Hat Pro didn't have power rails on either side, so I had to use a larger breadboard to make room for the 3 resistors (a SoftPot variable potentiometer and two rotary potentiometers). By using the larger breadboard, I was able to easily run a grounding jumper wire from the GND output of the Explorer Hat and positive jumper wire from the 5V output. Once I copied/pasted the code for the original potentiometer and created a new variable in the code called "blue", I created a 3rd variable called "green" for the SoftPot's voltage input.

It was also a challenge to set up the correct order of the 3 potentiometers on the breadboard to reflect the order of the 3 virtual colored bars. For example, I moved the SoftPot to the middle since it was controlling the middle green bar in Minecraft, and moved it's controlling jumper wire to the #1 analog input on the Explorer Hat Pro.

All in all, this final remix helped me get much more comfortable with editing the Python code within IDLE. I also liked the fact that the circuit was simple enough that I could devote more time to reworking the Python code instead of getting bogged down with building a complex circuit with multiple sensors, LEDS, resistors, etc.

For people trying to do a remix of this project, try using different sensors or potentiometers to alter the voltage readings being fed into the Explorer Hat Pro Analog inputs. Also, try altering the max height of the bars in the Python script to make the bars go higher or lower so they all don't have the same max height.


Controlling 3 virtual Minecraft bars (blue, green, red) with 3 potentiometers.


Fritzing Diagram of circuit and inputs to Explorer Hat Pro

Here is my final remix code:

import explorerhat
import explorercraft
import time

HEIGHT   = 50

red = explorercraft.BarGraph(1,0,0,50,50,explorercraft.WOOL_RED)

green = explorercraft.BarGraph(2,0,0,50,50,explorercraft.WOOL_GREEN)

blue = explorercraft.BarGraph(3,0,0,50,50,explorercraft.WOOL_BLUE)

while True:


    value2 = max(0,min(50,int(explorerhat.analog.one.read() * 10)))
    green.update(value2)
    
    value3 = max(0,min(50,int(explorerhat.analog.two.read() * 10)))
    blue.update(value3)

    value = max(0,min(50,int(explorerhat.analog.three.read() * 10)))
    red.update(value)
    
    print("red bar is {} green bar is {} blue bar is {}").format(value3,value2,value)

    time.sleep(0.1)

No comments:

Post a Comment