I am using an Ardunio UNO and since the ardunio outputs 5 volts I am trying to c
ID: 663170 • Letter: I
Question
I am using an Ardunio UNO and since the ardunio outputs 5 volts I am trying to create a Code that increments and decrements the voltage using 2 buttons, ButtonA will add 0.5 volts each time it is pressed and ButtonB will subtract 0.5 volts each time it is pressed. Here is my code can you please look over it and see what I did wrong? As I set up the circuit the LED which is my test Vout to make sure it works only to Brighten up to 2 volts and Dim to 0 volts my buttons still dont work can someone help me please!
HERE IS MY CODE:
int PWMPin = 6; // output pin supporting PWM
int buttonApin = 8; // buttonA to pin 9 PWM
int buttonBpin = 10; // buttonB to pin 10 PWM
int value = 0; // read the value at 0
int fadeValue = value;
float counter = 0;
void setup()
{
fadeValue = 0;
pinMode(buttonApin, INPUT);
pinMode(buttonBpin, INPUT);
pinMode(PWMPin, OUTPUT);
}
void loop()
{
int port = analogRead(0);
port = map(port, 0, 1023, 0, 255);
analogWrite(6, port);
if (digitalRead(buttonApin) == LOW)
{
if (counter >= 10)
{
counter = 10;
}
// fade from min to max in increments of 25.5 points: basically (0.5 volts)
fadeValue = 0;
fadeValue <= 255;
fadeValue = ++25.5;
{
// sets the value (range from 0 to 255):
analogWrite(PWMPin, fadeValue);
delay(300);
}
}
if (digitalRead(buttonBpin) == LOW, fadeValue)
{
if (counter <= 0)
{
counter = 0;
}
// fade from max to min in increments of 25.5 points: basically (0.5 volts)
fadeValue = 255;
fadeValue >= 0;
fadeValue = --25.5;
{
counter = fadeValue;
// sets the value (range from 0 to 255):
analogWrite(PWMPin, fadeValue);
delay(300);
}
}
}
Explanation / Answer
if (digitalRead(buttonApin) == LOW) and If (digitalRead(buttonBpin) == LOW, fadeValue)
why these two condition are different i mean digitalRead(X) return one thing only and LOW, fadeValue is wrong.
counter = fadeValue; // This line wrong bro i mean counter is always in range of (0,10) why you are assigning it 255; 229.5 ... extra extra
REST LOOK FINE.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.