Matrix keypad 1012_2 odditity

Legacy support with Phidget21
type11969
Phidgetsian
Posts: 6
Joined: Fri May 17, 2013 10:42 am
Contact:

Matrix keypad 1012_2 odditity

Postby type11969 » Fri May 17, 2013 2:03 pm

Greetings. I am using AC3 and the 1012_2 I/O board to run/read a membrane switch keypad that is electrically matrixed. Some background:

Keys 1, 2, and 3 are tied together and connected to output #9 on the I/O board
Keys 4, 5, and 6 are tied together and connected to output #12 on the I/O board
Keys 7, 8, and 9 are tied together and connected to output #15 on the I/O board
Keys 1, 4 and 7 are tied together and connected to input #14 on the I/O board

We can stop there since this is enough info to describe the error I am seeing.

Outputs are tied to a pullup resistor and a 5v source, so when the output is brought high, the input is tied to ground, neutralizing that line. In other words, if

Output 9 = false, output 12=true, output 15 = true - Key 1 has been hit
Output 12 = false, output 9=true, output 15 = true - Key 4 has been hit
Output 15 = false, output 12=true, output 9 = true - Key 7 has been hit

This code should be pretty straightforward to implement, but I am seeing the code report a button 4 press when button 1 is physically pressed, a button 7 press when button 4 is physically pressed, and a button 1 press when button 7 is physically pressed.

Should also be straightforward to debug considering that everything is just shifted by one, but when I query the outputs, I see that in the first cycle of my loop, even though I define the outputs to be 9 = false, 12 = true, and 15 = true, the outputs are reading 9 = false, 12= false, and 15=false. In the next increment of the loop, the outputs read 9 = false, 12 = true, and 15 = true, but at this point I am defining them to be 9=true, 12=false, 15=false. I don't understand why there is the initial error in output definition, nor why there is this lag.

Anyway, here is the code, please let me know if you see any issues:

Code: Select all

package  {
   
   import com.phidgets.*;
   import com.phidgets.events.*;
   import flash.events.*;
   import flash.display.*;
   import flash.utils.Timer;
   import com.greensock.*;
   import com.greensock.events.*;
   
   public class MoogKeypadTest extends MovieClip {
      
      public var phidgetIOBoard:PhidgetInterfaceKit;
      public var io:PhidgetInterfaceKit;
      
      public var inputs:Array;
      public var outputs:Array;
      
      
      public var inc:int = 0;
      
      public var keypadTimer:Timer;
      
      public function MoogKeypadTest() {
         
         if(stage) {
            init();
         } else {
            addEventListener(Event.ADDED_TO_STAGE, init);
         }
      }
      
      public function init():void {
         
         keypadTimer = new Timer(50, 0);
         keypadTimer.addEventListener( TimerEvent.TIMER, changeOutputStates );      
         initPhidgetIOBoard();
      }
      
      private function initPhidgetIOBoard():void {
         
         phidgetIOBoard = new PhidgetInterfaceKit();
         phidgetIOBoard.addEventListener(PhidgetEvent.DETACH, onPhidgetDetach);
         phidgetIOBoard.addEventListener(PhidgetEvent.ATTACH, onPhidgetAttachIOBoard);
         phidgetIOBoard.addEventListener(PhidgetEvent.CONNECT, onPhidgetConnect);
         phidgetIOBoard.addEventListener(PhidgetEvent.DISCONNECT, onPhidgetDisconnect);
         phidgetIOBoard.addEventListener(PhidgetErrorEvent.ERROR, onPhidgetError);
         phidgetIOBoard.open("localhost", 5002);
      }
      
      
      
      private function changeOutputStates( e:TimerEvent = null ):void {

            if( inc == 3 ) {
               
               inc = 0;
            }
            
            var a:int;
            var b:int;
            var c:int;
            
            if( inc == 0 ) {
               a = 9;
               b = 12;
               c = 15;
            }
            
            if( inc == 1 ) {
               c = 9;
               a = 12;
               b = 15;
            }
            
            if( inc == 2 ) {
               b = 9;
               c = 12;
               a = 15;
            }
            
            phidgetIOBoard.setOutputState( a, false );
            phidgetIOBoard.setOutputState( b, true );
            phidgetIOBoard.setOutputState( c, true );
            
            
            
            if( io.getInputState( 14 ) == true ) {
               
            
               checkOutputStates();
               
               if( inc == 0 ) {
                  
                  trace(" ############################## Button  1  press ############################### ");
               }
               
               if( inc == 1 ) {
                  
                  trace(" ############################## Button  4  press ############################### ");
               }
               
               if( inc == 2 ) {
                  
                  trace(" ############################## Button  7  press ############################### ");
               }
            }
               
            
            inc++;
         }
      }
      
      private function checkOutputStates( incrementor:int ):void {
         
         trace(" ############## ITERATION " + incrementor + " ################");
         
         trace( "9 is " + phidgetIOBoard.getOutputState(9) );
         trace( "12 is " + phidgetIOBoard.getOutputState(12) );
         trace( "15 is " + phidgetIOBoard.getOutputState(15) );
         
      }
      

      
      
      
      public function delayedStart():void {
         trace("Delayed start started!");
         keypadTimer.start();
      }
      
      private function onPhidgetDetach( e:PhidgetEvent ):void {
         
         trace("PHIDGET DETACH: " + e.Device.Name + ", Serial Number: " + e.Device.serialNumber.toString() + "\n" );
      }
      
      private function onPhidgetAttach( e:PhidgetEvent ):void {
         
         trace("PHIDGET ATTACH: " + e.Device.Name + ", Serial Number: " + e.Device.serialNumber.toString() + "\n" );
      }
      
      private function onPhidgetConnect( e:PhidgetEvent ):void {
         
         trace("PHIDGET CONNECT: " + e);
         
         
         
         //trace("PHIDGET CONNECT: " + e.Device.Name + ", Serial Number: " + e.Device.serialNumber.toString() + "\n" );
      }
      
      private function onPhidgetDisconnect( e:PhidgetEvent ):void {
         
         trace("PHIDGET DISCONNECT: " + e.Device.Name + ", Serial Number: " + e.Device.serialNumber.toString() + "\n" );
      }
      
      private function onPhidgetError( e:PhidgetErrorEvent ):void {
         
         //trace("PHIDGET ERROR: " + e.Device.Name + ", Serial Number: " + e.Device.serialNumber.toString() + "\n" );
         trace("PHIDGET ERROR: " + e );
      }
   }
}


type11969
Phidgetsian
Posts: 6
Joined: Fri May 17, 2013 10:42 am
Contact:

Re: Matrix keypad 1012_2 odditity

Postby type11969 » Mon May 20, 2013 7:59 am

Any thoughts? This has me stumped

User avatar
burley
Human-Cyborg Relations
Posts: 441
Joined: Tue Sep 27, 2011 2:37 pm
Location: Calgary
Contact:

Re: Matrix keypad 1012_2 odditity

Postby burley » Tue May 21, 2013 7:32 am

The keypad output ties the 1012's input to ground? That won't be effective, the inputs on the 1012 are active high. You need to pull them high in order to register a change.
Brian Burley
403-282-7335 ext. 6003
support@phidgets.com

type11969
Phidgetsian
Posts: 6
Joined: Fri May 17, 2013 10:42 am
Contact:

Re: Matrix keypad 1012_2 odditity

Postby type11969 » Tue May 21, 2013 7:46 am

Since the keypad is matrixed (keys 1, 4 and 7; 2,5 and 8; and 3 ,6 and 9 are on the same input and keys 1, 2 and 3; 4,5 and 6; and 7,8 and 9 are on the same output), I need to cycle through the outputs quickly, isolating one at a time by tying the other two to ground (bringing the outputs high on these two lines). So, for instance, if the outputs connected to 1,2 and 3; and 4, 5 and 6 are high, a press on any of these keys will not be registered by the phidgets board because, as you mentioned, a phidgets input needs to be brought high to register a keystroke. But this is what I want in this one instance of the loop. In this one instance, line 7,8 and 9 is electrically held at 5V, so if a high state is read on any of the inputs controlling keys 1,4 and 7; 2,5 and 8; or 3,6 and 9, I know that either key 7, 8 or 9 was pressed since all of the other keys are electrically held low by the output state I set in this one instance. Of course, in the next instance of the loop, I isolate a different output line and listen for an input, again being able to isolate which key was hit based on the state of the inputs and outputs. The challenge is being able to run through this loop fast enough to not miss keystrokes . . .

User avatar
burley
Human-Cyborg Relations
Posts: 441
Joined: Tue Sep 27, 2011 2:37 pm
Location: Calgary
Contact:

Re: Matrix keypad 1012_2 odditity

Postby burley » Tue May 21, 2013 10:18 am

Not a whole lot can be done unfortunately. Flash can only interact with devices via the WebService which introduces significant delays. If you need to have faster response time then you will likely need to switch to a different language which can access the devices locally which is faster.
Brian Burley
403-282-7335 ext. 6003
support@phidgets.com

type11969
Phidgetsian
Posts: 6
Joined: Fri May 17, 2013 10:42 am
Contact:

Re: Matrix keypad 1012_2 odditity

Postby type11969 » Tue May 21, 2013 10:31 am

Brian-

Can you make a recommendation for a preferred language? Unfortunately Flash gives us a lot of flexibility in terms of UI development, but of course these hardware limitations are a big problem. After running a few tests, it seems that the bottleneck is really setting the outputs. We cannot get below a 42ms loop time (without errors) when we are cycling through the outputs and checking the inputs. If we are just checking the inputs, we can get down to a 20ms loop time, which is probably good enough. Of course, with a USB connection and multiple gHz processors in my laptop, a 20ms loop time is embarrassingly slow. Anyway, our workaround might be to use an Arduino to cycle through the outputs, and use the phidgets board/flash to sense the Arduino output states (as inputs) along with the input lines from the keypad. Do you see any potential issues with this that I might be overlooking?

-Chris

User avatar
burley
Human-Cyborg Relations
Posts: 441
Joined: Tue Sep 27, 2011 2:37 pm
Location: Calgary
Contact:

Re: Matrix keypad 1012_2 odditity

Postby burley » Wed May 22, 2013 8:04 am

I would probably recommend one of the .NET languages.
Brian Burley
403-282-7335 ext. 6003
support@phidgets.com

type11969
Phidgetsian
Posts: 6
Joined: Fri May 17, 2013 10:42 am
Contact:

Re: Matrix keypad 1012_2 odditity

Postby type11969 » Wed May 22, 2013 8:15 am

Brian-

Thanks. Is it possible to configure some of the outputs on the board as inputs?

-Chris

User avatar
burley
Human-Cyborg Relations
Posts: 441
Joined: Tue Sep 27, 2011 2:37 pm
Location: Calgary
Contact:

Re: Matrix keypad 1012_2 odditity

Postby burley » Wed May 22, 2013 10:00 am

No, the inputs and outputs are predetermined and cannot be changed.
Brian Burley
403-282-7335 ext. 6003
support@phidgets.com

ericmason
Fresh meat
Posts: 1
Joined: Fri Aug 05, 2016 11:31 pm
Contact:

Re: Matrix keypad 1012_2 odditity

Postby ericmason » Wed Aug 10, 2016 10:59 pm

type11969 wrote:Since the keypad is matrixed (keys 1, 4 and 7; 2,5 and 8; and 3 ,6 and 9 are on the same input and keys 1, 2 and 3; 4,5 and 6; and 7,8 and 9 are on the same output), I need to cycle through the outputs quickly, isolating one at a time by tying the other two to ground (bringing the outputs high on these two lines). So, for instance, if the outputs connected to 1,2 and 3; and 4, 5 and 6 are high, a press on any of these keys will not be registered by the phidgets board because, as you mentioned, a phidgets input needs to be brought high to register a keystroke. But this is what I want in this one instance of the loop. In this one instance, line 7,8 and 9 is electrically held at 5V, so if a high state is read on any of the inputs controlling keys 1,4 and 7; 2,5 and 8; or 3,6 and 9, I know that either key 7, 8 or 9 was pressed since all of the other keys are electrically held low by the output state I set in this one instance. Of course, phenq works in the next instance of the loop, I isolate a different output line and listen for an input, again being able to isolate which key was hit based on the state of the inputs and outputs. The challenge is being able to run through this loop fast enough to not miss keystrokes . . .


Were you able to find a solution to this? or you changed the language? Being an Actionscript fan, I would be more then happy to see this being achieved. Flash gives best UI. .net is also good. but if you have less programming then flash is 100 times better.
Last edited by ericmason on Mon Sep 19, 2016 8:57 pm, edited 1 time in total.


Return to “ActionScript 3.0 - Flash CS3 / Flex / AIR”

Who is online

Users browsing this forum: No registered users and 5 guests