Responder Experiment V2.0
Responder Experiment V2.0
Overview
Specification
Button : Size: 6 x 6 x 5mm
Temperature: -30 ~ +70 Centigrade
Pin definition
za
Is the definition of Button pin:
ra
sm
1
Hardware required
Material diagram Material name Number
Button 4
LED 3
220/330Ω resistor 3
10KΩ resistor 4
USB Cable 1
UNO R3 1
za
Breadboard 1
ra
sm
2
Connection
Schematic
za
ra
sm
3
Connection diagram
za
ra
sm
4
Sample code
Note: sample code under the Sample code folder
int Redled=8; // set Red LED as “output”
int Yellowled=7; // set Yellow LED as “output”
int Greenled=6; // set Green LED as “output”
int Key1=5; // initialize pin for Red button
int Key2=4; // initialize pin for Yellow button
int Key3=3; // initialize pin for Green button
int KeyRest=2; // initialize pin for reset button
int Red;
int Yellow;
int Green;
void setup()
{
pinMode(Redled,OUTPUT);
pinMode(Yellowled,OUTPUT);
pinMode(Greenled,OUTPUT);
pinMode(Key1,INPUT);
pinMode(Key2,INPUT);
za
pinMode(Key3,INPUT);
pinMode(KeyRest,INPUT);
ra
}
void loop() // repeatedly read pins for buttons
{
sm
Red=digitalRead(Key1);
Yellow=digitalRead(Key2);
Green=digitalRead(Key3);
if(Red==HIGH)Red_YES();
if(Yellow==HIGH)Yellow_YES();
if(Green==HIGH)Green_YES();
}
void Red_YES() // execute the code until Red light is on; end cycle when reset button is
pressed
{
while(digitalRead(KeyRest)==0)
{
digitalWrite(Redled,HIGH);
digitalWrite(Greenled,LOW);
digitalWrite(Yellowled,LOW);
}
clear_led();
}
5
void Yellow_YES() // execute the code until Yellow light is on; end cycle when reset
button is pressed
{
while(digitalRead(KeyRest)==0)
{
digitalWrite(Redled,LOW);
digitalWrite(Greenled,LOW);
digitalWrite(Yellowled,HIGH);
}
clear_led();
}
void Green_YES() // execute the code until Green light is on; end cycle when reset
button is pressed
{
while(digitalRead(KeyRest)==0)
{
digitalWrite(Redled,LOW);
digitalWrite(Greenled,HIGH);
digitalWrite(Yellowled,LOW);
za
}
clear_led();
}
ra
digitalWrite(Redled,LOW);
digitalWrite(Greenled,LOW);
digitalWrite(Yellowled,LOW);
}
6
Example picture
za
ra
sm
7
Language reference
Tips:click on the following name to jump to the web page.
If you fail to open, use the Adobe reader to open this document.
digitalRead()
== (equality)
Application effect
Whichever button is pressed first, then the corresponding LED will be on!
******************************************************************************************
* About Smraza:
* We are a leading manufacturer of electronic components for Arduino and Raspberry
Pi.
* Official website: http://www.smraza.com/
* We have a professional engineering team dedicated to providing tutorials and
za
support to help you get started.
* If you have any technical questions, please feel free to contact our support staff via
email at [email protected]
ra
* We truly hope you enjoy the product, for more great products please visit our
Amazon US store: http://www.amazon.com/shops/smraza
sm