HI everyone, i connected leds and i control their state with the joystick and also their brightness with PWM, my problems are,
(1)if you look at the code a second i want to know how to increase the accuracy of the fade effect, [EDIT: i figured out that the fading isn’t accurate because of the joystick it self]
(2) why the heck my ledGreen won’t use PWM, i changed to another PWM pin but still not working, [EDIT: and i also changed my LED twice]
thanks for anyone answers, your helping the world to become a better place
byte swPin = 12; //button Pin
byte xPin = 0; // X axis Analog pin
byte yPin = 1;// Y axis Analog pin
byte ledBlue = 6;
byte ledGreen = 5;
byte ledYellow = 11;
byte ledRed = 10;
void setup() {
// put your setup code here, to run once:
pinMode(ledBlue, OUTPUT); // setting pin modes and starting Serial for debugging
pinMode(ledGreen, OUTPUT);
pinMode(ledRed, OUTPUT);
pinMode(ledYellow, OUTPUT);
pinMode(swPin, INPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
int xVal = analogRead(xPin);
int yVal = analogRead(yPin);
int xpVal = map(xVal, 0, 1023, 0, 255);
int ypVal = map(yVal, 0, 1023, 0, 255);
Serial.println(ypVal); //for debugging onlu
if (xpVal > 128) {
int xppVal = map(xpVal, 129, 255, 0, 255);
analogWrite(ledRed, xppVal);
}
else if (xVal < 128) {
int xpppVal = map(xpVal, 123, 0, 0, 255);
analogWrite(ledGreen, xpppVal);
}
else
{
digitalWrite(ledRed, LOW);
digitalWrite(ledGreen, LOW);
}
if (ypVal > 123) {
int yppVal = map(ypVal, 123, 255, 0, 255);
analogWrite(ledBlue, yppVal);
}
else if (ypVal < 123)
{
int ypppVal = map(ypVal, 123, 0, 0, 255);
analogWrite(ledYellow, ypppVal);
}
else
{
digitalWrite(ledBlue, LOW);
digitalWrite(ledYellow, LOW);
}
}