希望用这俩做出一个可以弹奏的小乐器,代码如下,可以编译但是插上没反应,求大神指点!
附代码(Keypad库已下载)
#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
{'0','1','2','3'},
{'4','5','6','7'},
{'8','9','A','B'},
{'C','D','E','F'}
};
byte rowPins[ROWS] = {3, 2, 1, 0}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {7, 6, 5, 4}; //connect to the column pinouts of the keypad
#define C1 262
#define C2 294
#define C3 330
#define C4 350
#define C5 393
#define C6 441
#define C7 495
//initialize an instance of class NewKeypad
Keypad keypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void setup(){
pinMode(8,OUTPUT);
}
void loop(){
char tune = keypad.getKey();
switch(tune)
{case 1:tone(8,C1,500);break;
case 2:tone(8,C2,500);break;
case 3:tone(8,C3,500);break;
case 4:tone(8,C4,500);break;
case 5:tone(8,C5,500);break;
case 6:tone(8,C6,500);break;
case 7:tone(8,C7,500);break;
default:noTone(8);break;
}
}
附代码(Keypad库已下载)
#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
{'0','1','2','3'},
{'4','5','6','7'},
{'8','9','A','B'},
{'C','D','E','F'}
};
byte rowPins[ROWS] = {3, 2, 1, 0}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {7, 6, 5, 4}; //connect to the column pinouts of the keypad
#define C1 262
#define C2 294
#define C3 330
#define C4 350
#define C5 393
#define C6 441
#define C7 495
//initialize an instance of class NewKeypad
Keypad keypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void setup(){
pinMode(8,OUTPUT);
}
void loop(){
char tune = keypad.getKey();
switch(tune)
{case 1:tone(8,C1,500);break;
case 2:tone(8,C2,500);break;
case 3:tone(8,C3,500);break;
case 4:tone(8,C4,500);break;
case 5:tone(8,C5,500);break;
case 6:tone(8,C6,500);break;
case 7:tone(8,C7,500);break;
default:noTone(8);break;
}
}

