# Analogue Input alongside RGB Keypad (Circuit Python)

**URL:** <https://forums.pimoroni.com/t/analogue-input-alongside-rgb-keypad-circuit-python/21305>\
**Category:** Support\
**Created:** [January 21, 2023, 5:48pm UTC](https://forums.pimoroni.com/t/analogue-input-alongside-rgb-keypad-circuit-python/21305 "2023-01-21T17:48:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![stevelondon](https://avatars.discourse-cdn.com/v4/letter/s/c6cbf5/32.png) [@stevelondon](https://forums.pimoroni.com/u/stevelondon)\
**Post date:** [January 21, 2023, 5:48pm UTC](https://forums.pimoroni.com/t/analogue-input-alongside-rgb-keypad-circuit-python/21305/1 "2023-01-21T17:48:56Z")

</div>

Hi

I am trying to read analogue input on the Pi Pico (using GP26 Board.A0) monitoring a RobotDyn 4x4 Analogue Keypad (different resistance per button). This has 3 pins: GND, VCC (connected to 3.3v) and OUTPUT which i connect to GP26 Board.A0

If I do this on just a pi pico, unconnected to the Pimoroni RGB Keypad - it works fine.

When the pi pico is plugged into the Pimoroni RGB Keypad I get loads of random values. (See the check() function in the code below)

So far I am hypothesizing that maybe the various things going on in the RGB Keypad is some how either

a) making the analogue pin “float”  
or  
b) is not delivering a constant 3.3v causing fluctuations (could it be that the 3.3v output pin varies because the current draw of all the leds is making the voltage fluctuate?)

## Here is the class for the analogue keypad

```auto
class AnKeyPad:
    def __init__ (self, midi, nId, pin, callback=None):
        self.midi = midi
        self.nId = nId
        self.prevVoltage = 0
        self.pin=pin
        self.analogue = AnalogIn(pin)
        self.callback = callback
        self.currVoltage=0.0
        self.notches = [29,33,40,49,54,57,59,62,69,74,78,83,97,106,115,126]
        self.notchMap=[0,4,8,12,1,5,9,13,2,6,10,14,3,7,11,15]
        self.midiNoteStart = 36
        self.velocity=100
        self.lastPressed = time.monotonic()
        
    def get_voltage(self, voltage):
        return int((voltage * 127) / 65536)
    
    def check(self):
        global noteBasher
        now = time.monotonic()
        currVoltage = self.get_voltage(self.analogue.value)
        if currVoltage<25: #basically a note-off type event - when user stops pressing
            self.prevVoltage=currVoltage
            return    
        
        if abs(self.prevVoltage-currVoltage)>3 and now-self.lastPressed >.2:
            print(currVoltage)
            nearestIdx = min(range(len(self.notches)), key=lambda i: abs(self.notches[i]-currVoltage))            
            self.prevVoltage=currVoltage 
            noteBasher.noteOn(self.midiNoteStart+self.notchMap[nearestIdx])
            self.lastPressed = time.monotonic()
            if self.callback!=None:
                self.callback(self.nId, currVoltage-4)

```

Anyone have any ideas what might be going wrong - or just any suggestions of things to check

Thanks

Steve
