Question

By using Arduino write a code that connects two LEDs to two push-buttons. Each button controls...

By using Arduino write a code that connects two LEDs to two push-buttons. Each button controls the state of its connected LED. The LEDs can be in one of two states: Blink-mode or Off-mode. When a button-press event is detected, its connected LED will begin blinking (turning on and off) and when a button-press is detected, its connected LED will turn off. The application should blink one of the LEDs at a rate of 1 second, and the other LED at a rate of 2 seconds. (By using Arduino coding )

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

void setup() { pinMode(2,INPUT);//button 1 pinMode(3,INPUT);//button 2 pinMode(5,OUTPUT);//led 1 pinMode(6,OUTPUT);//led 2 } int led1state=0,led2state=0; void blinkLed(int pin,int delay) { digitalWrite(pin,HIGH); delay(delay*1000); digitalWrite(pin,LOW); delay(delay*1000); } void offLed(int pin) { digitalWrite(pin,LOW); } void loop() { int i=digitalRead(2); int j=digitalRead(3); if(i>=1) { if(led1state==0) led1state=1; else led1state=0; } if(j>=1) { if(led2state==0) led2state=1; else led2state=0; } if(led1state==1) { blinkLed(1,1);//first led for 2 seconds of delay } else { offLed(1); } if(led2state==1) { blinkLed(2,2);//second led for 2 seconds of delay } else { offLed(2); } }

Code reference for indentation:

Explanation:

Connect push buttons to pin 2, pin 3; Led to 5, 6 pins. Ground them properly. Now two variables led1state, led2state is used to store the current state of the led. blinkLed takes two inputs, pin number and number of seconds the pin should be under delay. Now when a state change is detected the states are toggled. This continues until next push button change is detected  

Add a comment
Know the answer?
Add Answer to:
By using Arduino write a code that connects two LEDs to two push-buttons. Each button controls...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write an Arduino code to read the current temperature using the LM35 temperature sensor. The code...

    Write an Arduino code to read the current temperature using the LM35 temperature sensor. The code should include the following if the temperature is more than 45 "C: • Turn ON red LED, and after 1 second turn ON the yellow LED, and after another 2 seconds tum On the Green LED. One second later the three LEDS should start blinking (all LEDs OFF for 0.5 seconds, then all LEDS ON for 1 minute), and turn OFF all LEDs after...

  • You are to create a new application that will execute on your Arduino platform based upon...

    You are to create a new application that will execute on your Arduino platform based upon the Blink example that is available in the Arduino Examples folder that you downloaded as part of the IDE. Your application will use a toggle switch to interface with the user. The application will operate by controlling the LEDs based upon the position of the toggle switch. If the user moves the LEDs until new user input is provided. When the user moves the...

  • I need help with doing these tasks for code composer Lab 3 - Branching, Push Button...

    I need help with doing these tasks for code composer Lab 3 - Branching, Push Button and LEDs-Reading Assignment in this lab, we are going to control a LED via a push button- using general purpose digital 10 for both input (button) and output (LED) on port 1 - using Code Composer Studio. Furthermore, we are going to use a branch instruction to create an IF-ELSE structure in assembly to determine if the LED should be lit up based on...

  • Car Parking Sensor Build a simple Car parking sensor system using the Arduino. Use the provided U...

    i want the arduino code please We were unable to transcribe this imageCar Parking Sensor Build a simple Car parking sensor system using the Arduino. Use the provided Ultrasonic Sensor to measure the distance between the sensor and an object. When an object is detected within a defined range, a buzzer must beep repeatedly at a certain rate. And as the object gets closer, the beeping gets faster. Your design must meet the following requirements 1. Calibrate the range of...

  • I am doing an Arduino Uno project where I made a "Simon says" memory game with 3 neopixel LED str...

    I am doing an Arduino Uno project where I made a "Simon says" memory game with 3 neopixel LED strips and 3 - ultrasonics. I have them working independently but I need to combine the code so they work together. Here is what I have: Memory Game #define PLAYER_WAIT_TIME 2000 // The time allowed between button presses - 2s byte sequence[100]; // Storage for the light sequence byte curLen = 0; // Current length of the sequence byte inputCount =...

  • Could you please show me how I can drw those circuits. please using (NI Multisim 14)...

    Could you please show me how I can drw those circuits. please using (NI Multisim 14) Optocoupler Objectives Use an ohmmeter to determine the condition of the optoisolator. Observe the operation of an optocoupler. Determine the maximum frequency response of the optocoupler. Required Materials (1) Dual DC power supply (1) Function generator (1) Oscilloscope (2) Multimeters (1) Optocoupler (ECG3040) (1) 3.9ΚΩ resistor (1) 220 resistor Introduction An optoisolator is a hybrid integrated circuit that contains an LED on one side...

  • In this lab, you will design a finite state machine to control the tail lights of...

    In this lab, you will design a finite state machine to control the tail lights of an unsual car. There are three lights on each side that operate in sequence to indicate thedirection of a turn. Figure ! shows the tail lights and Figure 2 shows the flashing sequence for (a) left turns and (b) right rums. ZOTTAS Figure 28:8: BCECECece BCECECECes BCECECECB BCECECBCB 8888 Figure 2 Part 1 - FSM Design Start with designing the state transition diagram for...

  • If you’re using Visual Studio Community 2015, as requested, the instructions below should be exact but...

    If you’re using Visual Studio Community 2015, as requested, the instructions below should be exact but minor discrepancies may require you to adjust. If you are attempting this assignment using another version of Visual Studio, you can expect differences in the look, feel, and/or step-by-step instructions below and you’ll have to determine the equivalent actions or operations for your version on your own. INTRODUCTION: In this assignment, you will develop some of the logic for, and then work with, the...

  • summarizr the followung info and write them in your own words and break them into different...

    summarizr the followung info and write them in your own words and break them into different key points.   6.5 Metering Chamber: 6.5.1 The minimum size of the metering box is governed by the metering area required to obtain a representative test area for the specimen (see 7.2) and for maintenance of reasonable test accuracy. For example, for specimens incorporating air spaces or stud spaces, the metering area shall span an integral number of spaces (see 5.5). The depth of...

  • summatize the following info and break them into differeng key points. write them in yojr own...

    summatize the following info and break them into differeng key points. write them in yojr own words   apartus 6.1 Introduction—The design of a successful hot box appa- ratus is influenced by many factors. Before beginning the design of an apparatus meeting this standard, the designer shall review the discussion on the limitations and accuracy, Section 13, discussions of the energy flows in a hot box, Annex A2, the metering box wall loss flow, Annex A3, and flanking loss, Annex...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT