KY-004 Tryk Knap Module bruges som en switch module til projekter, hvor du ment kan bruge den som en digital afbryder.
Tekniske detaljer:
Rating: 50mA 12VDC.
Contact Resistance : 50mΩ max. (initial)
Insulation Resistance: 100MΩ.(minDC 250V)
Dielectric Strength : AC250V.(50/60Hz for 1minute)
Electrically Life: 100,000cycles.
Environment Temperature: -25℃~+105℃.
Operating Force: 180/230.(±20gf)
Seal Temperature: 250℃-280℃.
Eksempel
Her viser vi et hurtig eksempel på hvordan du sammen sætter dette modul til en “Arduino Uno R3”, Brug “Knappen” til at aktivere LED On/Off.
Du skal bruge:
- Arduino Uno R3
- Mini-B USB stik
- Print Push Button
- 2x 100Ohm Modstand
- Breadboard
- Dupont Breadboard Kabel
Alle dele kan købes i webshoppen. Klik på navnet for at blive viderestillet til produktet.

Kode (Engangs tryk – Forbliver On/Off)
int ButtomPin = 10;         // the number of the input pin
int LEDPin = 7;       // the number of the output pin
int state = HIGH;      // the current state of the output pin
int reading;           // the current reading from the input pin
int previous = LOW;    // the previous reading from the input pin
// the follow variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long time = 0;         // the last time the output pin was toggled
long debounce = 200;   // the debounce time, increase if the output flickers
void setup()
{
  pinMode(ButtomPin, INPUT);
  pinMode(LEDPin, OUTPUT);
}
void loop()
{
  reading = digitalRead(ButtomPin);
  // if the input just went from LOW and HIGH and we've waited long enough
  // to ignore any noise on the circuit, toggle the output pin and remember
  // the time
  if (reading == HIGH && previous == LOW && millis() - time > debounce) {
    if (state == HIGH)
      state = LOW;
    else
      state = HIGH;
    time = millis();    
  }
  digitalWrite(LEDPin, state);
  previous = reading;
}
Kode (On/Off)
// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 10;     // the number of the pushbutton pin
const int ledPin =  7;      // 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);
  }
}
Download
Kontakt os
Du er altid velkommen til at kontakte os på info@ardustore.dk, eller sende os en besked via messenger (Klik her) og vi vil hjælpe dig.
 
				







 
															 
															
Anmeldelser
Der er endnu ikke nogle anmeldelser.