2017/05/30

maxresdefault

Over this week I made a breadboard version of a input using a mechanical keyswitch, the breadboarding and wiring was based on the picture above. I used a modified code to fit my needs from http://www.makeuseof.com/tag/make-custom-shortcut-buttons-arduino/

 

int keys[] = {2, 3, 4, 5, 6, 7, 8, 9, 10};

void setup() {
 // put your setup code here, to run once:
 Keyboard.begin(); // setup keyboard
 for (int i = 2; i < 11; ++i) {
 // initilize pins
 pinMode(i, INPUT);
 }
}

void loop() {
 // put your main code here, to run repeatedly:
 for (int i = 2; i < 11; ++i) {
 // check buttons
 if(readButton(i)) {
 doAction(i); 
 }
 }
}

boolean readButton(int pin) {
 // check and debounce buttons
 if (digitalRead(pin) == HIGH) {
 delay(10);
 if (digitalRead(pin) == HIGH) {
 return true;
 }
 }
 return false;
}

void doAction(int pin) {
 // perform tasks
 switch (pin) {
 case 2:
 Keyboard.println("Testing for keypad");
 }
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s