10723| 10
|
[项目] 触控钢琴 |
本帖最后由 gada888 于 2019-3-31 14:53 编辑 触控钢琴 调试设备:Arduino uno MP3 module 8欧喇叭 touchPiano.rar TTP229 16 Key Capacitive Keypad 是个IIC模块,1.....VCC (2.4 - 5.5V) 2.....GND 3.....SCL (serial clock in) 4.....SDO (serial data out) 5.....OUT 1 (key 1 state) 6.....OUT 2 (key 2 state) 7.....OUT 3 (key 3 state) 8.....OUT 4 (key 4 state) 9.....OUT 5 (key 5 state) 10...OUT 6 (key 6 state) 11...OUT 7 (key 7 state) 12...OUT 8 (key 8 state) [mw_shl_code=applescript,true]/*FILE: TTP229_16_Key_Capacitive_Touch_Example DATE: 25/02/15 VERSION:0.1 REVISIONS: 25/02/15 Createdversion 0.1 Thisis an exampleof howtouse the Hobby Components16 key capacitive touch keypad(HCMODU0079). Thisexamplesketch will read the currentstate of the ofthekeypadand if a key ispressed outputitskey number tothe serial port. The sketch assumesthatthe keypadis configuredto 16 keyactive low mode byshortingpadsP1-3 andP1-P4 together (see schematic orsport forum for more information).Connect thekeypad to your Arduinoas follows: Keypad......Arduino VCC.........+5V GND.........GND SCL.........Digital pin8 SDO.........Digital pin9 You may copy,alter andreusethiscodein any way you like, but please leave referenceto HobbyComponents.com in your comments if you redistribute this code. Thissoftwaremay not be useddirectly for the purpose of promotingproducts that directly competewith Hobby Components Ltd'sownrange of products. THISSOFTWAREISPROVIDED"ASIS".HOBBY COMPONENTS MAKES NO WARRANTIES, WHETHER EXPRESS,IMPLIED OR STATUTORY, INCLUDING, BUTNOT LIMITED TO, IMPLIED WARRANTIES OFMERCHANTABILITYANDFITNESS FOR A PARTICULARPURPOSE,ACCURACY OR LACKOF NEGLIGENCE. HOBBYCOMPONENTS SHALL NOT, IN ANY CIRCUMSTANCES, BELIABLE FOR ANY DAMAGES INCLUDING, BUT NOTLIMITED TO, SPECIAL, INCIDENTAL OR CONSEQUENTIALDAMAGES FORANYREASON WHATSOEVER.*/ /*Definethedigital pins used for theclock and data */ #define SCL_PIN 8 #define SDO_PIN 9 /*Used to storethe key state */ byteKey; voidsetup() { /*Initialise the serial interface */ Serial.begin(9600); /*Configure theclock anddatapins */ pinMode(SCL_PIN,OUTPUT); pinMode(SDO_PIN,INPUT); } /*Main program */ voidloop() { /*Readthecurrent state of thekeypad */ Key = Read_Keypad(); /*If akeyhas been pressed output it tothe serial port */ if(Key) Serial.println(Key); /*Waitalittlebeforereadingagain so notto flood the serial port*/ delay(100); } /*Read thestate of the keypad */ byteRead_Keypad(void) { byteCount; byteKey_State=0; /*Pulse the clock pin 16 times(one for each key of thekeypad) and readthe stateof the data pinon each pulse*/ for(Count=1;Count <=16;Count++) { digitalWrite(SCL_PIN,LOW); /*Ifthedatapin islow(active low mode) then storethe current keynumber*/ if(!digitalRead(SDO_PIN)) Key_State = Count; digitalWrite(SCL_PIN,HIGH); } return Key_State; }[/mw_shl_code] |
谢谢您,这么快回复,虽然没有详细说明,但您的回复让我看到您的支持,我会一点点去学,感谢您,祝您一切顺利! |
© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed