Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Note that all the color value variables are used to dim the respective LED.
- //Meaning, the axis on the joystick associated with redValue will dim RED
- //instead of making that direction RED.
- // const int SW_pin = 2; //Switch currently unused
- const int X_pin = 0; // VRx connected to A0
- const int Y_pin = 1; // VRy connected to A1
- #define RED 11 // Red to Digital 11
- #define BLUE 10 // Blue to Digital 10
- #define GREEN 9 // Green to Digital 9
- void setup() {
- // pinMode(SW_pin, INPUT); //Swith currently unused
- // digitalWrite(SW_pin, HIGH); //Swith currently unused
- // Serial.begin(9600); //Serial was used for debugging. Turn on to see values.
- pinMode(RED, OUTPUT);
- pinMode(GREEN, OUTPUT);
- pinMode(BLUE, OUTPUT);
- }
- void loop() {
- int x = 0;
- int y = 0;
- x = analogRead(X_pin); //Read VRx normally
- y = abs(1023-(analogRead(Y_pin))); //Invert VRy read, as the module is inverted
- int redValue = 0;
- int greenValue = 0;
- int blueValue = 0;
- int xValue = 0; //xValue is later reffered to as "douse," as it's main role is to douse the red and and blue LEDs
- xValue = (map(y, 512, 1023, 0, 255)); //Douse is the upper half of the Y axis
- xValue = constrain (xValue, 0, 255); //Set the upper half range to 0 thru 255
- greenValue = (map(y, 0, 512, 0, 255)); //Set the green control to the lower half of the Y axis
- 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
- blueValue = (map(x, 512, 1023, 255, 0))-xValue; //Set the blue control to the right half of the X axis, then subtract the "Douse" value
- blueValue = constrain(blueValue, 0, 255); //Make sure the range of power for each output is 0 to 255
- redValue = constrain(redValue, 0, 255);
- greenValue = constrain(greenValue, 0, 255);
- analogWrite(RED, redValue); //Make the lights turn on.
- analogWrite(BLUE, blueValue); // :)
- analogWrite(GREEN, greenValue);
- Serial.print("X-axis: "); //I'm letting this still execute, but nothing will display
- Serial.println((x)); //until the Serial.begin(baud) is turned back on.
- Serial.print("Y-axis: ");
- Serial.println((y));
- Serial.print("Red=");
- Serial.println(redValue);
- Serial.print("Blue=");
- Serial.println(blueValue);
- Serial.print("Green=");
- Serial.println(greenValue);
- Serial.print("Douse="); //Remember, "DOUSE" is the xValue and it's role is to turn off red and blue LEDs
- Serial.println(xValue);
- Serial.print("\n");
- // delay(500); //Used in debugging so one can read the serial output. Keep off to keep LED control real-time
- }
Add Comment
Please, Sign In to add comment