Write Arduino code to read the input state of pin3 and output the value to the o
ID: 2085840 • Letter: W
Question
Write Arduino code to read the input state of pin3 and output the value to the onboard LED.
(a) Create hardware that causes pin 3 to read a high value when a button switch is pushed and a low value when the switch isn’t pushed. Breadboard the needed hardware.
This is what I have so far, and I need extra help on the code. Or, I'm unsure if this is the correct appoarch. The hardware I have is my Ardunio UNO, LED red light, and 1kilo-Ohm resistor.
int outPin = 3;
void setup()
{
pinMode(outPin,OUTPUT); //initalize pin 3 on Ardunio
pinMode(pushbutton; INPUT); //initalize output button
}
void loop()
{
button = digitalRead(pushbutton);
if(button == HIGH)
{
digitalWrite(outPin, HIGH);
delay(100);
digitalWrite(outPin, LOW);
}
else
{
???
}
}
Explanation / Answer
U have used the correct approach but it just need little changes in void loop
Void loop()
{
button = digitialRead (pushbotton);
if (pushbotton==High)
{
digitalWrite (outPin , HIGH);
// this is the case when button is pushed, it will make LED at pin3 glow
delay(2000); // 2 seconds delay
}
else
{
digitalWrite ( outPin , LOW );
// When switch is not pushed theLED will remain off
delay(2000);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.