Arduino示例代码讲解:Project 07 - Keyboard 键盘
- Project 07 - Keyboard 键盘
-
- 程序功能概述
-
-
- 功能:
- 硬件要求:
- 输出:
-
- 代码结构
-
-
- 全局变量
- `setup()` 函数
- `loop()` 函数
- 读取电位器值:
- 打印电位器值:
- 播放音调:
-
- 运行过程
- 注意事项
Project 07 - Keyboard 键盘
/*
Arduino Starter Kit example
Project 7 - Keyboard
This sketch is written to accompany Project 7 in the
Arduino Starter Kit
Parts required:
two 10 kilohm resistors
1 Megohm resistor
220 ohm resistor
4 pushbuttons
piezo
Created 13 September 2012
by Scott Fitzgerald
http://arduino.cc/starterKit
This 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 communication
Serial.begin(9600);
}
void loop() {
// create a local variable to hold the input on pin A0
int keyVal = analogRead(A0);
// send the value from A0 to the Serial Monitor
Serial.println(keyVal);
// play the note corresponding to each value on A0
if (keyVal == 1023) {
// play the first frequency in the array o