Question

In: Computer Science

Try to control 3 LEDs by Potentiometer. Take 3 LEDs and connect it up the same...

Try to control 3 LEDs by Potentiometer. Take 3 LEDs and connect it up the same way we use to do and connect the potentiometer to one of the analog pins. Observe the values coming out from it. Program the code such a way, when it runs, first, LED 1 should turn ON, then after a certain amount of value range, LED 1 should be OFF and LED 2 should be ON. Again, the same way, LED 2 should be OFF and LED 3 should be ON. The value ranges from 0-1023. It is up to you how these values should be divided into 3 parts. It would be nice if you would use Nested loops because there are more than two conditions.

using Arudrino and Sparkfun kit

Solutions

Expert Solution

const int potpin=A0;// potentiometer pin to connection
const int led1=3;//led1,led2,led3 connections
const int led2=4;
const int led3=5;//
int val=0;//variable to store pot values
void setup() {
  // put your setup code here, to run once:
  pinMode(led1,OUTPUT);
pinMode(led2,OUTPUT);
pinMode(led3,OUTPUT);
pinMode(potpin,INPUT);

}

void loop() {
  val=analogRead(potpin);
  //pot values divided as 0 to 341=led1 on,342 to 682=led2 on,683 to 1023=led3 on
  if(val>=0 && val<=341)
  {
    digitalWrite(led1,HIGH);//led1 is on
    digitalWrite(led2,LOW);//led2 is off
    digitalWrite(led3,LOW);//led3 is off
  }
  else if(val>=342 && val<=682)
  {
    digitalWrite(led2,HIGH);//led2 is on
    digitalWrite(led1,LOW);//led1 is off
    digitalWrite(led3,LOW);//led3 is off
  }
  if(val>=683 && val<=1023)
  {
    digitalWrite(led3,HIGH);//led3 is on
    digitalWrite(led1,LOW);//led1 is off
    digitalWrite(led2,LOW);//led2 is off
  }
  

}


Related Solutions

Arduino Project - Part 1 • Connect 3 LEDs on 3 digital pins • Blink LEDs...
Arduino Project - Part 1 • Connect 3 LEDs on 3 digital pins • Blink LEDs at: – 1 at 1 Hz – 2 at 4 Hz – 3 at 5 Hz • Blink LEDs at: – 1 Hz – 3 Hz – 5 Hz 36 What to submit • 2 Arduino files – one for 1,4,5 Hz blinking – one for 1,3,5 Hz blinking
Build a circuit for arcade game. You have 3 LEDS and 1 button. the LEDs should...
Build a circuit for arcade game. You have 3 LEDS and 1 button. the LEDs should recycle through 000,100,110,111,011, 001(back to 000). The user needs to hit the button during the 111 cycle 3 times in a row to win. The win is shown as an LED which is HIGH if the user won the last attempt of 3 presses. The win LED will be LOW otherwise
1. True or False? Plants take up nitrogen from the atmosphere in the same way that...
1. True or False? Plants take up nitrogen from the atmosphere in the same way that they take up atmospheric carbon. 2. Large animal aggregations such as bird colonies, herds of large herbivores, and shoals of fish provide "safety in numbers" from predators. As a result, individuals in larger groups have higher survival & greater rates of reproduction than individuals in smaller groups. This represents an example of which of the following? A. Positive density dependence B. Negative density dependence...
There is something wrong with my arduino lab. I want my four leds to light up...
There is something wrong with my arduino lab. I want my four leds to light up one after the other. Then the speaker plays music, and 4 leds change with music. But my code only makes one of them work. Please help me modify my code const int switchPin = 8; unsigned long previousTime = 0; int switchState = 0; int prevSwitchState = 0; int led = 2; // 600000 = 10 minutes in milliseconds long interval = 1000; int...
1. If you connect a 9 v battery up to a 7 Ω resistor and a...
1. If you connect a 9 v battery up to a 7 Ω resistor and a 10 μF capacitor for a very long time, what would the current in the circuit be? 2. What is the time constant in an RC circuit and how is it found? 3. In your own words what is meant by an RC circuit and give an example of one you might find in the real world.
Q2. Write an 8051 C program that uses 3 temperature sensors (TS1, TS2, TS3),   3 LEDs...
Q2. Write an 8051 C program that uses 3 temperature sensors (TS1, TS2, TS3),   3 LEDs (GreenLED, BlueLED and RedLED) and 1 buzzer (BUZZ). Monitor the temperature sensors such that whenever any of the sensor goes high, the buzzer will produce a sound and at the same time, its corresponding LED blinks 3 times. You may use any of the I/O Port Pins.     SOLUTION: C PROGRAM
Three (3) companies supply the same part. All three companies operate in-control processes for the single...
Three (3) companies supply the same part. All three companies operate in-control processes for the single quality characteristic of part-length. All three companies have a mean part-length equal to 17. The "red company" has a part-length standard deviation of 0.29 for the parts they produce. The "blue company" has a part-length standard deviation of 0.37 for the parts they produce. The "green company" has a part-length standard deviation of 0.20 for the parts they produce. The part-length specification has a...
Do students perform the same when they take an exam alone as when they take an...
Do students perform the same when they take an exam alone as when they take an exam in a classroom setting? Eight students were given two tests of equal difficulty. They took one test in a solitary room and they took the other in a room filled with other students. The results are shown below. Exam Scores Alone 96 76 73 71 85 87 75 86 Classroom 89 68 67 62 79 80 73 86 Assume a Normal distribution. What...
A series of vertical curves connect a 3% upgrade, a 2% downgrade, and another 3% upgrade...
A series of vertical curves connect a 3% upgrade, a 2% downgrade, and another 3% upgrade moving west to east. These curves are designed such that they connect directly to one another (i.e., the PVT of the first curve is the PVC of the second curve). If the design speed of the alignment is 60 mi/h, what is the elevation difference between the two road segments (i.e., the vertical difference between the PVC of the first curve and the PVT...
Write the recurrence for each of the following two problems. Try to come up with the...
Write the recurrence for each of the following two problems. Try to come up with the solution using your understanding. 1) Maximal subarray problem 2) Weighted interval selection problem
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT