Arduino示例代码讲解:Project 07 - Keyboard 键盘
Arduino示例代码讲解:Project 07 - Keyboard 键盘
- Project 07 - Keyboard 键盘
- 程序功能概述
- 功能:
- 硬件要求:
- 输出:
- 代码结构
- 全局变量
- `setup()` 函数
- `loop()` 函数
- 读取电位器值:
- 打印电位器值:
- 播放音调:
- 运行过程
- 注意事项
Project 07 - Keyboard 键盘
/*Arduino Starter Kit exampleProject 7 - KeyboardThis sketch is written to accompany Project 7 in theArduino Starter KitParts required:two 10 kilohm resistors1 Megohm resistor220 ohm resistor4 pushbuttonspiezoCreated 13 September 2012by Scott Fitzgeraldhttp://arduino.cc/starterKitThis example code is part of the public domain
*/// create an array of notes
// the numbers below correspond to
// the frequencies of middle C, D, E, and F
int notes[] = {262, 294, 330, 349};void setup() {//start serial communicationSerial.begin(9600);
}void loop() {// create a local variable to hold the input on pin A0int keyVal = analogRead(A0);// send the value from A0 to the Serial MonitorSerial.println(keyVal);// play the note corresponding to each value on A0if (keyVal == 1023) {// play the first frequency in the array o