Question

Arduino: Make a circuit that will turn on LEDs based on directions of a joystick as...

Arduino:

Make a circuit that will turn on LEDs based on directions of a joystick as follows (3 LEDs for x axis and 3 LEDs for y axis):

* For x axis, RED at the left, GREEN at the middle, and BLUE at the right.

* For y axis, RED at the up, GREEN at the middle, and BLUE at the down.

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

const int X_axis = 0; // analog pin connected to X output of the joystick
const int Y_axis = 1; // analog pin connected to Y output of the joystick
int left = 5;
int middle = 6;
int right = 7;
int down = 8;
int up = 9;
void setup()
{
Serial.begin(115200);
pinMode(left, OUTPUT);
pinMode(right, OUTPUT);
pinMode(middle, OUTPUT);
pinMode(up, OUTPUT);
pinMode(down, OUTPUT);

digitalWrite( left, LOW );
digitalWrite( right, LOW );
digitalWrite( middle, LOW );
digitalWrite( up, LOW );
digitalWrite( down, LOW );

}

void loop()
{
Serial.print("X-axis: ");
Serial.print(analogRead(X_axis));
Serial.print("\n");
Serial.print("Y-axis: ");
Serial.println(analogRead(Y_axis));
Serial.print("\n");
if (Y_axis <= 10)
{
digitalWrite(down, HIGH);
}
else
{digitalWrite(down, LOW);}
if (Y_axis >= 990)
{
digitalWrite(up, HIGH);
}
else
{digitalWrite(up, LOW);}
if (X_axis >= 990)
{
digitalWrite(right, HIGH);
}
else
{digitalWrite(right, LOW);}
if (X_axis <= 10)
{
digitalWrite(left, HIGH);
}
else
{digitalWrite(left, LOW);}
if(550 > X_axis > 490 && 550 > Y_axis > 490)
{
digitalWrite(middle, HIGH);
}
else
{digitalWrite(middle, LOW);}
delay(100);
}
/*Extreme analog value of a joystick is usually 1000 to 1050 and lowest value is around 0.
* When joystick is pulled to its extreme left, the analog value of X_axis should be almost zero.
* When joystick is pulled to its extreme right, the analog value of X_axis should be around 1000.
* Similarly when stick is pulled to its extreme up,the analog value of the Y_axis should be around 1000.
* When joystick is pulled to its extreme down, the analog value of the Y_axis should be almost 0.
* And when the stick is in the middle, analog value of both X_axis and Y_axis will be around 500.
*/

Now make the connection as shown below.

Add a comment
Know the answer?
Add Answer to:
Arduino: Make a circuit that will turn on LEDs based on directions of a joystick as...
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
  • .HuErioHe Three LEDs (one red, one green, one blue) turn on when a number 0-7 is...

    .HuErioHe Three LEDs (one red, one green, one blue) turn on when a number 0-7 is passed through. Red turns on with even numbers, green turns on with odd numbers, blue turns on with multiples of 3. Zero means they are all off, seven means they are all on. Set-up the appropriate truth table, simplify using K-maps. Implement, using LogiSim, the simplified logic circuit with optimal number of logic gates.

  • 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...

  • Problem 10 Use the following circuit to answer the next four questions. Recall that the resistor...

    Problem 10 Use the following circuit to answer the next four questions. Recall that the resistor enclosed in a circle with two arrows is a photoresistor/photocell. The photoresistor will be used to control the circuit's behavior. If the room is dark, the red LED will illuminate. In moderate light, the yellow LED will illuminate. In bright light, the green LED will illuminate. The reading from the photoresistor at pin AO is assigned to the integer variable, "photo_value. ☆ ☆ Red...

  • Directions: Using the graph of each function, identify the parent function, then write an equation for...

    Directions: Using the graph of each function, identify the parent function, then write an equation for the function under each transformation. 11. a) Parent Function: b) Translate 4 units down and 3 units left c) Vertically stretch by a factor of 2, then translate 5 units left: 12 a) Parent Function: b) Translate 3 units up and 8 units right: c) Horizontally compress by a factor of %, then reflect in the y-axis a) Parent Function: 13. b) Horizontally stretch...

  • 1. A data set that includes the shows on a station during the day would be...

    1. A data set that includes the shows on a station during the day would be classified as what type of data? nominal, ordinal, interval, ratio 2. What type of data collection might be best to estimate the amount of time individuals spend socializing? survey, observational, experiment, simulation 3. What type of data collection might be best to study how many books students bring into the media center during finals week? experiment, observational, simulation, survey 4. You need to study...

  • Word Problem) Two two-way streets meet at an intersection controlled by a four-way traffic light. In...

    Word Problem) Two two-way streets meet at an intersection controlled by a four-way traffic light. In the east and west directions, the lights cycle from green to yellow to red. The south-facing lights do the same thing, except that they are red when the east-west lights are green or yellow, and vice versa. However, the north-facing lights are augmented with a green left turn arrow. They cycle red-green arrow-yellow arrow-green-yellow-red. Consider the following additional problem specifications: When the green or...

  • Design an audio level indicator & amplifier circuit that lights up a different number of LEDs...

    Design an audio level indicator & amplifier circuit that lights up a different number of LEDs based the volume of the input signal and the circuit must turn on an LED when turned on and have at least 4 levels of audio indication using LEDs.The circuit must have a microphone and an aux input, easily switchable from one input to the other. The amplified sound output should measure 70 dB at 3 feet away from the speaker(Speaker= approx. 8ohm load)....

  • Experiment D: Conductivities of Solutions Purpose: To record the conductivity of each solution of ammonia, vinegar,...

    Experiment D: Conductivities of Solutions Purpose: To record the conductivity of each solution of ammonia, vinegar, calcium hydroxide, sodium bicarbonate, sodium chloride, and rubbing alcohol, using the conductivity apparatus. 0 Energizer On/Off Button On/Off Switch Conductivity Apparatus Notice on the circuit board that there is a button or switch to turn on/off the apparatus and two LEDs 9 (light emitting diodes). One LED will light up red and the other will light up green. If there is a yellow button,...

  • Lab 1-Lab Portion Part I Copy the Blink program from Figure 1-13 (page 17) in the textbook and run it on your Arduino. After verifying that the Blink program works, modify the program to make the...

    Lab 1-Lab Portion Part I Copy the Blink program from Figure 1-13 (page 17) in the textbook and run it on your Arduino. After verifying that the Blink program works, modify the program to make the on-board LED attached to pin #13 blink out "SOS" in Morse code. Use a 2 750 millisecond for long pulses. 50 millisecond for short pulses and a Part 2, Write a program that uses two pushbuttons to increase or decrease the brightness of the...

  • 119 Reference Page - PRECALCULUS AND COLLEGE ALGEBRA Starting with the reference function y=x2, rewrite the...

    119 Reference Page - PRECALCULUS AND COLLEGE ALGEBRA Starting with the reference function y=x2, rewrite the function and plot, based on the adjustments given. 1. Translate the reference function left. New function, y--- 2. Translate the reference function 3 down and 4 right. New function, y=--- 3. Translate the reference function 4 left and reflect about x axis. New function, y=- 120 - Reference Page PRECALCULUS AND COLLEGE ALGEBRA Starting with the reference function y=x3, rewrite the function and plot,...

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