Question

In: Computer Science

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 will be all the combinations of three colors and of course red, blue and green)

Solutions

Expert Solution

Here our task is to create an arduino program which produce RED BLUE GREEN colour from an rgbled using 3 for loops

Points to remember before coding

  • we have do drive led through analoge pins hence 3 variables should create for stores the pin number at which red blue green is going to be connected
  • create a for loop which iterate for some number (say 50) and turn on one colour pin using Analogue write(255)
  • after closing the for loop turn  off the same pin by analogwrite(0) and introduce some delay.Repaet above 2 steps for other colours

CODE

Working

(screenshots taken while simulating above code are shown below)

Text version of the code is given below

int red=A0; //declaring variables at which led doing to be connected
int green=A1;
int blue=A2;
int i,j,k; /iterating variables for for-loops
void setup() {   
pinMode(red,OUTPUT); //setting led pins as output
pinMode(green,OUTPUT);
pinMode(red,OUTPUT);
}
void loop() {
for(i=0;i<50;i++){ // for loop for red
analogWrite(red,255); //turning red on
}
analogWrite(red,0); //turning red off after loop
  
delay(200); //delay

for(i=0;i<50;i++){
analogWrite(blue,255);
}
analogWrite(blue,0);
  
delay(200);
  
for(i=0;i<50;i++){
analogWrite(green,255);
}
analogWrite(green,0);
delay(200);
}

Note :But remember the above task can be easily implemented without a for loop as follow  


Related Solutions

I am working on an Arduino Project. I would like to build a controllable RGB LED...
I am working on an Arduino Project. I would like to build a controllable RGB LED Nightlight (with a debounce code included). With each time pushing the button I want a different color. like the following Initial state = LED off first press= LED turns on Red second Press = LED turns on Green third Press = LED turns on Blue Fourth Press = LED turns on Purple Fifth Press = LED turns on Teal sixth press= LED turns on...
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 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
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!
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
Using an arduino, breadboard,  ultrasonic sensor, buzzer, lcd and red led display distance in centimeters, If needed,...
Using an arduino, breadboard,  ultrasonic sensor, buzzer, lcd and red led display distance in centimeters, If needed, use a rotary potentiometer, male to male cable (m-m) female to male cable (f-m) or any resistor provided in the kit. display distance in centimeters to lcd. If the object is in distance, turn on Active buzzer(play sound) and turn on red led. If the object is not in range, display out of range or "Object now close'.  on the lcd, make sure the buzzer...
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
I want to make picture compress program in matlab use eigenmatrix in RGB with PCA. This...
I want to make picture compress program in matlab use eigenmatrix in RGB with PCA. This code listed below. But this code is fail. I want to make the picture have a colour, but in my program the picture is still colorless. Can you fix my code? clc clear all picture = im2double(imread('picture1.jpg')); Red = picture(:,:,1); premean = mean(Red(:)); premax = max(Red(:)); premin = min(Red(:)); x = size(Red,1); y = size(Red,2); Z = ones(x,y)*premean; A = (Red - Z)*(1/premax -...
1. IN C LANGUAGE: Write a code that makes the MSP430 blink the red LED and...
1. IN C LANGUAGE: 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
Hi there, I need mpx2100ap arduino code do I need an amplifier to make this work...
Hi there, I need mpx2100ap arduino code do I need an amplifier to make this work ?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT