![]() ![]() What are the downsides of not using the power supply, or plugging the power supply to the Leonardo instead of using it as an external power supply? I have no experience doing something like this.įirst, my LEDs are specified as 12V, so I should probably use the power supply to power them. So my questions are more related on how to wire this up. I was thinking to use 8 for the buttons, 8 for the button LEDs and 4 for the joystick (no space for the joystick LED ) I would like to make something similar to the "reaction games" that you can find in some arcades where you need to hit the button that lights up. So my project consists of lighting the LEDs with the PC "game" and react to the button presses. I'm currently at the step of buying components.ġ 8-way joystick with 12V LED (4 switches) delay(500) //Used in debugging so one can read the serial output.This is my first project so I apologize for my nobby questions. Serial.print("Douse=") //Remember, "DOUSE" is the xValue and it's role is to turn off red and blue LEDs Serial.println((x)) //until the Serial.begin(baud) is turned back on. Serial.print("X-axis: ") //I'm letting this still execute, but nothing will display GreenValue = constrain(greenValue, 0, 255) ĪnalogWrite(RED, redValue) //Make the lights turn on. RedValue = (map(x, 0, 512, 0, 255))-xValue //Set the red control to the left half of the X axis, then subtract the "Douse" valueīlueValue = (map(x, 512, 1023, 255, 0))-xValue //Set the blue control to the right half of the X axis, then subtract the "Douse" valueīlueValue = constrain(blueValue, 0, 255) //Make sure the range of power for each output is 0 to 255 GreenValue = (map(y, 0, 512, 0, 255)) //Set the green control to the lower half of the Y axis XValue = constrain (xValue, 0, 255) //Set the upper half range to 0 thru 255 XValue = (map(y, 512, 1023, 0, 255)) //Douse is the upper half of the Y axis Int xValue = 0 //xValue is later reffered to as "douse," as it's main role is to douse the red and and blue LEDs ![]() Y = abs(1023-(analogRead(Y_pin))) //Invert VRy read, as the module is inverted ![]() X = analogRead(X_pin) //Read VRx normally Serial.begin(9600) //Serial was used for debugging. digitalWrite(SW_pin, HIGH) //Swith currently unused pinMode(SW_pin, INPUT) //Swith currently unused const int SW_pin = 2 //Switch currently unusedĬonst int X_pin = 0 // VRx connected to A0Ĭonst int Y_pin = 1 // VRy connected to A1 Meaning, the axis on the joystick associated with redValue will dim RED Note that all the color value variables are used to dim the respective LED. So, I'm just going to post my code here for those looking for a more beginner level Joystick controlled RGB LED. Found other posts where people were looking for the same thing, but never really got their questions answered. I tried looking up if anyone else had done it, and they have, but when reading it, it just felt like their code was complicated, so I set out to make a simple one. I finished the joystick tutorial and thought it would be fun to have it control an RGB LED. I've been working my way through my Elegoo project box tutorials, but after every lesson, I try to branch off and figure out how to use what I just learned.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |