Puzzle - Button 按键

来自Duinopeak_COM
跳转至: 导航搜索

产品简介


Button A.jpg
Puzzle - Button是一个瞬时按键。一般情况输出LOW。

规格参数

  • LED 从13端口连接至地
  • 按键从+5v连接至端口2
  • 10k的电阻从地连接到端口2
  • 几乎每块arduino板上都有一个LED连接至端口13

应用示例


Asd.jpg

下面的例子演示了如何用Puzzle- Button来开或关LED。

 //Turns on and off a light emitting diode(LED) connected to digital pin 13, when pressing a pushbutton attached to pin 2. 
 /*
 The circuit:
 * LED attached from pin 13 to ground 
 * pushbutton attached to pin 2 from +5V
 * 10K resistor attached to pin 2 from ground
 * Note: on most Arduinos there is already an LED on the board
 attached to pin 13.
 This example code is in the public domain.
 http://www.arduino.cc/en/Tutorial/Button
 */
 // constants won't change. They're used here to 
 // set pin numbers:
 const int buttonPin = 2;     // the number of the pushbutton pin
 const int ledPin =  13;      // the number of the LED pin
 // variables will change:
 int buttonState = 0;         // variable for reading the pushbutton status
 void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);      
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);     
 }
 void loop(){
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);
  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {     
    // turn LED on:    
    digitalWrite(ledPin, HIGH);  
  } 
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW); 
  }
 }

这里提供另外一种瞬时按键的有趣使用方法:

请按照以下接线方式接线即可:
Button operation.jpg

首先把下面的代码下载到你的Arduino上:

const int buttonPin = 2;     // the number of the pushbutton pin
int buttonState = 0;         // variable for reading the pushbutton status
void setup() {
  // initialize the serial communication:
  Serial.begin(9600);
  pinMode(buttonPin, INPUT);     
}

void loop(){
  if(digitalRead(2) == 1){
    Serial.println('!');
  } else {
    Serial.println(analogRead(A0));//just read the noise from A0
  }
  delay(1);
}

接着你需要从下面资源中下载按键的Processing的代码:
2014-11-02 09h04 29.png

  println(Serial.list());
  // Open whatever port is the one you're using.
  myPort = new Serial(this, Serial.list()[2], 9600);

运行程序时,你将会从这里看到
2014-11-02 09h04 44.png
然后把串口号,前面的数字代替 Serial.list()[2]中的2就行了,这样子,你就让Processing正确的和Arduino建立了联系了。 然后打开Processing运行上面的代码, 这就是这个小小玩法的一个有趣截图,让你的按键动作可视化了,当然按下的瞬间不免会产生一些毛刺,所以这里也能够正确的反映出来。
2014-11-02 09h10 59.png

资源


Puzzle - Button 按键原理图PDF: 文件:Puzzle Button schematic.pdf

Puzzle - Button 按键Processing: 文件:Processing button.zip

如何购买

Duinopeak 官方淘宝商城
Button 按键购买链接

支持

如果你有什么建议或者好的点子, 你可以来我们的DuinoPeak论坛参与讨论.

外部链接

链接到外部网页将会给你提供更多应用创意,文档/数据表或软件库

视频