I'm trying to create a code using an ArdunioArduino Uno board to increment and decrement the output voltage of the ArdunioArduino Uno which is 5 volts and I need to step it up to 10 volts which I have done below.
The things that are missing on the schematic are two buttons. I want to be able to increment 0.5 volts with each press of Button-A until the ArdunioArduino is at 5 volts. With Button-B I want to be able to lower the voltage by 0.5 volts with each press of the button till value is 0.
int PWMPin = 6; // output pin supporting PWM
int buttonApin = 9; // buttonA to pin 9 PWM
int buttonBpin = 10; // buttonB to pin 10 PWM
float value = 0; // read the value at 0
int fadeValue = value;
void setup()
{
Serial.begin(9600); //initialize serial communication at 9600 baud
pinMode(buttonApin, INPUT_PULLUP);
pinMode(buttonBpin, INPUT_PULLUP);
pinMode(PWMPin, OUTPUT);
}
void loop()
{
{
int port = analogRead(0);
port = map(port, 0, 10, 0, 255);
analogWrite(6, port);
}
{
if (digitalRead(buttonApin) == LOW, fadeValue)
{
// fade from min to max in increments of 25.5 points: basically (0.5 volts)
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=25.5)
digitalWrite(PWMPin, fadeValue);
// sets the value (range from 0 to 255):
Serial.println(PWMPin);
analogWrite(PWMPin, fadeValue);
}
}
{
if (digitalRead(buttonBpin) == LOW, fadeValue)
{
// fade from max to min in increments of 25.5 points:
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=25.5)
digitalWrite(PWMPin, fadeValue);
// sets the value (range from 0 to 255): basically (0.5 volts)
analogWrite(PWMPin, fadeValue);
}
}
}
int PWMPin = 6; // output pin supporting PWM
int buttonApin = 9; // buttonA to pin 9 PWM
int buttonBpin = 10; // buttonB to pin 10 PWM
float value = 0; // read the value at 0
int fadeValue = value;
void setup()
{
Serial.begin(9600); //initialize serial communication at 9600 baud
pinMode(buttonApin, INPUT_PULLUP);
pinMode(buttonBpin, INPUT_PULLUP);
pinMode(PWMPin, OUTPUT);
}
void loop()
{
{
int port = analogRead(0);
port = map(port, 0, 10, 0, 255);
analogWrite(6, port);
}
{
if (digitalRead(buttonApin) == LOW, fadeValue)
{
// fade from min to max in increments of 25.5 points: basically (0.5 volts)
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=25.5)
digitalWrite(PWMPin, fadeValue);
// sets the value (range from 0 to 255):
Serial.println(PWMPin);
analogWrite(PWMPin, fadeValue);
}
}
{
if (digitalRead(buttonBpin) == LOW, fadeValue)
{
// fade from max to min in increments of 25.5 points:
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=25.5)
digitalWrite(PWMPin, fadeValue);
// sets the value (range from 0 to 255): basically (0.5 volts)
analogWrite(PWMPin, fadeValue);
}
}
}
