Buy an Axon, Axon II, or Axon Mote and build a great robot, while helping to support SoR.
0 Members and 1 Guest are viewing this topic.
http://www.robotshop.com/sfe-keypad-12-button.html
int keypad(void) { sbi(DDRE,PE4); cbi(DDRE,PE4); sbi(DDRE,PE6); cbi(DDRE,PE6); sbi(DDRE,PE2); cbi(DDRE,PE2); int k=0; int tempkey[1]; for(int i=0;i<2;i++) { PORT_OFF(PORTE,7); PORT_OFF(PORTE,5); PORT_ON(PORTE,3); delay_ms(50); if(bit_is_set(PINE,4)) { key=1; } else if(bit_is_set(PINE,2)) { key=2; } else if(bit_is_set(PINE,6)) { key=3; } PORT_OFF(PORTE,3); PORT_OFF(PORTE,7); PORT_ON(PORTE,5); delay_ms(50); if(bit_is_set(PINE,4)){ key = 10; } else if(bit_is_set(PINE,2)){ key = 0; } else if(bit_is_set(PINE,6)){ key = 11; } PORT_OFF(PORTE,5); PORT_OFF(PORTE,3); PORT_ON(PORTE,7); delay_ms(50); if(bit_is_set(PINE,4)){ key = 4; } else if(bit_is_set(PINE,2)){ key = 5; } else if(bit_is_set(PINE,6)){ key = 6; } tempkey[k]=key; k++; } if(tempkey[0]==tempkey[1]) key=tempkey[1]; else key=15; return(key); }
Now, lets say you push the button labeled '1'. What happens? Well, if you follow the lines, COL1 and ROW1 get activated at the same time. Make sense?
Now, load up WebbotLib Project Designer for your Axon. On the left, click Basic, then drag Digital Input into your project. A window comes up. Name the input (COL1, COL2, ROW1, etc), select an input pin, and check the button that says 'Use Internal pullup resistor'.
set all column pins to highfor each row pin{set row pin to high for each column pin { if column pin is low, button was pressed. do something }set row pin to low}