Last active
August 26, 2018 01:33
-
-
Save anekos/eee55724b1aa22298337b65b8ef46adc to your computer and use it in GitHub Desktop.
静電タッチキーボード TTP229用のコード
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
/** | |
* Original code: http://forum.hobbycomponents.com/viewtopic.php?f=73&t=1781 | |
* | |
* | |
* This is an example of how to use the Hobby Components 16 key capacitive touch | |
* keypad (HCMODU0079). This example sketch will read the current state of the | |
* of the keypad and if a key is pressed output its key number to the serial port. | |
* | |
* The sketch assumes that the keypad is configured to 16 key active low mode | |
* by shorting pads P1-3 and P1-P4 together (see schematic or sport forum for more | |
* information). Connect the keypad to your Arduino as follows: | |
* | |
* Keypad......Arduino | |
* VCC.........+5V | |
* GND.........GND | |
* SCL.........Digital pin 8 | |
* SDO.........Digital pin 9 | |
* | |
* You may copy, alter and reuse this code in any way you like, but please leave | |
* reference to HobbyComponents.com in your comments if you redistribute this code. | |
* | |
* This software may not be used directly for the purpose of promoting products that | |
* directly compete with Hobby Components Ltd's own range of products. | |
* | |
* THIS SOFTWARE IS PROVIDED "AS IS". HOBBY COMPONENTS MAKES NO WARRANTIES, | |
* WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED | |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ACCURACY OR | |
* LACK OF NEGLIGENCE. HOBBY COMPONENTS SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE | |
* FOR ANY DAMAGES INCLUDING, BUT NOT LIMITED TO, SPECIAL, INCIDENTAL OR | |
* CONSEQUENTIAL DAMAGES FOR ANY REASON WHATSOEVER. | |
*/ | |
#include "Keyboard.h" | |
/* Define the digital pins used for the clock and data */ | |
#define SCL_PIN 8 | |
#define SDO_PIN 9 | |
void setup() | |
{ | |
Keyboard.begin(); | |
/* Configure the clock and data pins */ | |
pinMode(SCL_PIN, OUTPUT); | |
pinMode(SDO_PIN, INPUT); | |
} | |
byte prev = 0; | |
/* Main program */ | |
void loop() | |
{ | |
/* Read the current state of the keypad */ | |
byte now = Read_Keypad(); | |
/* If a key has been pressed output it to the serial port */ | |
if ((now != prev) && now) { | |
Keyboard.write('a' + now); | |
} | |
prev = now; | |
} | |
/* Read the state of the keypad */ | |
byte Read_Keypad(void) | |
{ | |
byte Count; | |
byte Key_State = 0; | |
/* Pulse the clock pin 16 times (one for each key of the keypad) | |
and read the state of the data pin on each pulse */ | |
for(Count = 1; Count <= 16; Count++) | |
{ | |
digitalWrite(SCL_PIN, LOW); | |
/* If the data pin is low (active low mode) then store the | |
current key number */ | |
if (!digitalRead(SDO_PIN)) | |
Key_State = Count; | |
digitalWrite(SCL_PIN, HIGH); | |
} | |
return Key_State; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment