Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For Arduino Uno: Write a program that has TWO pushbuttons wired active low, one

ID: 3721017 • Letter: F

Question

For Arduino Uno:

Write a program that has TWO pushbuttons wired active low, one on pin 4 and one on pin 9. ONE led light is wired to pin 11. When the button on pin 4 is pushed, the led will turn on for approximately 3 seconds. If the button on pin 9 is pushed during these 3 seconds, the led will start flashing at 2 Hz for 5 seconds. If the button is not pushed during the 3 seconds, the led will turn off. The cycle repeats.

(Follow the instructions given in the problem above, two push buttons and one led)

Explanation / Answer

elect]

const int buttonPin =2

const int buttonPin1=2
const int buttonPin2=3

set pin numbers:
const int buttonPin1 = 2;
const int buttonPin2 = 3;   
const int ledPin = 13;   :
int buttonState = 0;   


void setup() {
pinMode(buttonPin2, INPUT);
}

void loop(){
buttonState = digitalRead(buttonPin1);
buttonState = digitalRead(buttonPin2);:

buttonState = digitalRead(buttonPin1);
buttonState = digitalRead(buttonPin2);
if (buttonState == HIGH) {   
digitalWrite(ledPin, HIGH);
}
else {

digitalWrite(ledPin, LOW);
}
}

const int buttonPin1 = 2; // the number of the pushbutton pin 2
const int buttonPin2 = 3; // the number of the pushbutton pin 3
const int ledPin = 13; // the number of the LED pin


int buttonState1 = 0; // variable for reading the pushbutton status
int buttonState2 = 0;


void setup() {

pinMode(ledPin, OUTPUT);
pinMode(buttonPin1, INPUT);
:
pinMode(buttonPin2, INPUT);
}

void loop(){

if (buttonState1 == HIGH) {
  
digitalWrite(ledPin, HIGH);
}
if (buttonState2 == HIGH) {
  
digitalWrite(ledPin, LOW);
}
}

#include <Button.h> //http://www.arduino.cc/playground/Code/Button

Button button1 = Button(11,PULLUP);
Button button2 = Button(12,PULLUP);

void setup(){
//setup
}

void loop(){
if (button1.uniquePress()){ //you need to release this button in order for it to trigger again

}
if (button2.uniquePress()){ //you need to release this button in order for it to trigger again
//do action associated with button1
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote