Question

In: Computer Science

FOR ARDUINO PROGRAMMING; WRITE CODE TO FIT THE BELOW REQUIREMENTS 1. LED 3 TURNS ON IN...

FOR ARDUINO PROGRAMMING;

WRITE CODE TO FIT THE BELOW REQUIREMENTS

1. LED 3 TURNS ON IN DARK CONDITIONS AND OFF IN LIGHT CONDITIONS

2. LED 4 TURNS ON WITH FIRST BUTTON PRESS AND STAYS ON UNTIL A SECOND BUTTON PRESS

Solutions

Expert Solution

Answer (1) = We need to glow LED in Dark conditions and off LED in Light conditions. To sense the light we need a "Light Dependent Register", which sense the light and generate a analog waveform of frequency according to the light intensity. The arduino code for this purpose is as below. Comments are shown by "//" operator at beginning of line.

source code :

int led = 3;

// main function

void setup(){

pinMode(led,OUTPUT);

}

// loop to manage led functionality

void loop(){

// connect Light Dependent Register to A1 and read the waveform using analogRead

int intensity=analogRead(A1);

// if intensity is greater than 50 means it is light conditions and off the led

if(intensity>50){

digitalWrite(led,LOW);

}

// if intensity is lesser than 50 then it is dark situation and on the led

else{

digitalWrite(led,HIGH);

}

}

Answer (2) = We need to manage led as "if we press any button then led is on, and if we press another button then led is off". The arduino code for this purpose is as below. comments are shown by "//" operator at beginning of line.

source code:

// button position in arduino

int btn = 2;

// led position in arduino
int led = 4;

// initially assume led is off
int state = false;
void setup(){
pinMode(led, OUTPUT);
pinMode(btn, INPUT_PULLUP);
}

void loop(){

// if button pressed then change the state and write state to led
if (digitalRead(btn) == true) {
state = !state;
digitalWrite(led, state);
}

// while loop always on the led until next time button is not pressed
while(digitalRead(btn) == true);
delay(50);
}


Related Solutions

FOR ARDUINO PROGRAMMING; WRITE CODE TO FIT THE BELOW REQUIREMENTS; 1. LED 1 TURNS ON AND...
FOR ARDUINO PROGRAMMING; WRITE CODE TO FIT THE BELOW REQUIREMENTS; 1. LED 1 TURNS ON AND STAYS ON THE ENTIRE TIME THE BOARD IS RUNNING EXCEPT AT 30 SECOND INTERVALS THEN LED 1 TURNS OFF AND BACK ON 2. LED 2 TURNS ON IN LIGHT CONDITIONS AND OFF IN DARK CONDITION THANK YOU!
Write the following in C language for Arduino: Write a program that turns on the LED...
Write the following in C language for Arduino: Write a program that turns on the LED at 25%, 50%, 75%, 100%, and then 0% brightness with a one second delay in between each change. Remember you are going to need to use a PWM pin and use the "analogWrite" command. The maximum value for our Arduino R3 boards is 255 and you need five steps (25%, 50%, 75%, 100%, and 0%) so you will need to determine the values for...
THIS IS FOR ARDUINO PROGRAMMING Write code that checks the sensor data and meets the following...
THIS IS FOR ARDUINO PROGRAMMING Write code that checks the sensor data and meets the following conditions: For night conditions, turn on white LED 1 For day conditions, turn off white LED 1 Code should check intervals every 5 seconds. NEED THE BELOW CODE TO FIT THE ABOVE REQUIREMENTS. const int lightSensor = 5; //light sensor variable float sensValue = 0; //variable to hold sensor readings const int button = 3; //pin for button reads const int LED1 = 5;...
Using Arduino to blink an LED in morse code. Morse code is used as one of...
Using Arduino to blink an LED in morse code. Morse code is used as one of the methods for communications. It consists of a series of “dit” and “dah” symbols. (i) Develop an Arduino program to produce a Morse code to express the phrase “We are students” using Pin #13 (connect an LED that is in series with a 220-Ω resistor to Pins #13 to view the information sent via the Morse code). Express one “dit” with LED on for...
1.. Write a code that LED1 (Red LED- P1.0) turns ON when after you push S1(push...
1.. Write a code that LED1 (Red LED- P1.0) turns ON when after you push S1(push button - P1.1) five times and stays OFF forever after that. 2.. Write a code that LED1 (Red LED- P1.0) turns OFF and LED2 (Red LED- P9.7) Turns ON after you push S1(push button -P1.1) five times and they stay that way forever.
4. Write a code that S1(push button -P1.1) turns LED1 (Red LED- P1.0) ON and stays...
4. Write a code that S1(push button -P1.1) turns LED1 (Red LED- P1.0) ON and stays on when you push once and turns off and stays OFF when you push 3 times. This should repeat forever. 5. Write a code that S2(push button -P1.2) turns LED2 (Red LED- P9.7) ON and stays ON when you push once and turns OFF and stays OFF when you push 3 times. This should repeat five times. 6. Write a code that LED2 (Red...
CODE WITH ARDUINO: With an RGB Led, Use the iterative loop (for loop) to make red,...
CODE WITH ARDUINO: With an RGB Led, Use the iterative loop (for loop) to make red, blue, and green. Use ‘analogWrite’ command inside the 'for loop.' Use the value ranges from 0-255 for this command. So, to activate any of the pins, the value should be 255. To turn off 0. pattern: First for loop Red light – delay – Second for loop for blue light – delay - Third for loop for green light - delay. (The resulting lights...
Write the following in C language for Arduino: Write a program that increases the LED brightness...
Write the following in C language for Arduino: Write a program that increases the LED brightness in five steps with each press of the button. Remember you are going to using a digital input and the "digitalRead" command. You are going to need to use a PWM pin and use the "analogWrite" command. The maximum value for our Arduino R3 boards is 255 and you need five steps (25%, 50%, 75%, 100%, and 0%) so you will need to determine...
1. Write a code that makes the MSP430 blink the red LED and the green LED...
1. Write a code that makes the MSP430 blink the red LED and the green LED at the same time. The two LEDs should be on at the same time and then off at the same time
Produce program code to facilitate LED and switch interface with a microcontroller-based development board (Arduino). Explain...
Produce program code to facilitate LED and switch interface with a microcontroller-based development board (Arduino). Explain the programming process and interface circuits required
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT