Skip to content

Instantly share code, notes, and snippets.

Created February 27, 2018 12:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/5be163739f77fb646fb2a0321500f6be to your computer and use it in GitHub Desktop.
Save anonymous/5be163739f77fb646fb2a0321500f6be to your computer and use it in GitHub Desktop.
16 capacitive switches
// Use any 2 pins you like - this is NOT I2C ;-)
#define SCL_PIN 8
#define SDO_PIN 9
byte Key;
void setup()
{
Serial.begin(9600);
Serial.println("Cap key board");
pinMode(SCL_PIN, OUTPUT);
pinMode(SDO_PIN, INPUT);
}
void loop()
{
Key = Read_Keypad();
if (Key)
{
Serial.println(Key);
delay(200);
}
}
byte Read_Keypad(void)
{
byte pinCount;
byte KeyCount = 0;
for (pinCount = 1; pinCount <= 16; pinCount++)
{
digitalWrite(SCL_PIN, LOW);
if (digitalRead(SDO_PIN) == LOW)
{
KeyCount = pinCount;
}
digitalWrite(SCL_PIN, HIGH);
}
return KeyCount;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment