Materials:
1.SAGOO UNO 1 Block;
2. Key Module 1 blocks;
3. A number of DuPont lines.
Steps:
1. Follow the Connect button module and UNO;
Sagoo uno Pin Key Module Pin
3V3 <------------------------------------> V (Power)
GND <------------------------------------> G (Power)
Pin2 <------------------------------------> S (signal)
2. Launch the Arduino IDE software, open File->examples->digital->button, compile and download to UNO motherboard;
3. The default UNO board LED light is on, press the button led off, release the LED light.
Demo Video: http://v.youku.com/v_show/id_XMTI4NjM2NTg0MA==.html
Schematic diagram:
Code:
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'll 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 are high:
if (buttonstate = = high) {
Turn LED on:
Digitalwrite (Ledpin, high);
}
else {
Turn LED off:
Digitalwrite (Ledpin, low);
}
}
Description
Hardware: Uno motherboard through digital Pin2 read the state of the button module, when the key output is high, lit LED lights, conversely, off LED lights. The key module is output high by default and press the key to output low level.
Software:
const int buttonpin = 2; --Defines the constant button as the number 2;
const int ledpin = 13; --Define constant Ledpin as number 13;
int buttonstate = 0;---Defines the default state of a PIN variable to 0;
ButtonState = Digitalread (Buttonpin);--Read the status value of the digital foot 2 to the variable buttonstate;
/*----------------------------------------------------
If...else ... Statement to determine the key state and perform the corresponding action
-----------------------------------------------------*/
if (buttonstate = = high) {
Turn LED on:
Digitalwrite (Ledpin, high);
}
else {
Turn LED off:
Digitalwrite (Ledpin, low);
}
Four, key control led light off