Please use code tags when posting code
type
** **[code]** **
paste your code after that
type
** **[/code]** **
I have done if for you for the code in reply #2
int increment = 30;
int val;
int up = LOW;
int lastval = 5;
const int upPin = 3;
const int downPin = 4;
const int Mosfet = 11;
void setup ()
{
pinMode(3, INPUT);
pinMode(4, INPUT);
pinMode(13, OUTPUT);
Serial.begin(9600);
int up = digitalRead(upPin);
}
void loop()
{
if (up == HIGH) val = lastval + increment;
(lastval = val);
digitalWrite(Mosfet, val);
Serial.println(val);
if (up == LOW) val = lastval;
(lastval = val);
digitalWrite(Mosfet, val);
Serial.println(val);
delay(5);
}
You have a global variable 'up' (declared before setup()). In setup you use a different variable 'up'.
As you never read upPin in loop() and 'up' is initialised with LOW, only the second if condition in loop() will be satisfied; val = lastval + increment; will never be executed. I guess you need
void loop()
{
up = digitalRead(upPin);
if (up == HIGH) val = lastval + increment;
...
...
...
}
Lastly, the second parameter for digitalWrite will switch the pin LOW if val equals zero and HIGH in all other cases. So digitalWrite(Mosfet, 5) and digitalWrite(Mosfet, 500) will do exactly the same; maybe you want to use analogWrite ![]()