Last active
August 9, 2017 07:02
-
-
Save kingardor/856621be2837c2ebb4f14078273225a7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Connections | |
VCC ----- 5V/3.3V | |
GND ----- GND | |
SCL -----> D12 | |
SDO -----> D13 | |
Note: If using 3.3V logic boards like Pro Mini or ESP8266, connect VCC to 3.3V. | |
*/ | |
#define pulse 12 | |
#define data 13 | |
int old = 0; | |
void setup() { | |
Serial.begin(9600); | |
pinMode(pulse, OUTPUT); | |
pinMode(data, INPUT); | |
} | |
void loop() { | |
int Key = getkey(); | |
if (Key!=0&Key!=old) { | |
Serial.print("BUTTON PRESSED:--> "); | |
Serial.println(Key); | |
} | |
old = Key; | |
delay(100); //Debounce | |
} | |
byte getkey(void) { | |
byte cnt; | |
byte num = 0; | |
for(cnt = 1; cnt < 17; cnt++) { | |
digitalWrite(pulse, LOW); | |
if(digitalRead(data) == 0) | |
num = cnt; | |
digitalWrite(pulse, HIGH); | |
} | |
return num; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment