Quick $5 for the first working response

Hi All,

I would like to offer $5 usd to the first person that can add potentiometer adjustment to the code bellow.
Payment will be made via paypal

Currently the code will move a servo horn 90° from a starting position of 5° when a button is pressed. It will also hold the position until the button is released.

What I need is a potentiometer to be able to adjust the value of 90° to a value between 10° - 180°

The code can be posted as a reply, so that anyone can use/see it.

If this is not possible or if I'm too cheap!, please feel free to let me know.
Thanks

#include <Servo.h>

Servo myservo;  // create servo object to control a servo 
                // a maximum of eight servo objects can be created 
 
 int pos = 5
 ;    // variable to store the servo position 
 int button = 2;  // The button will be on Pin 7 
 
 
 void setup() 
{ 
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
 pinMode(pos, OUTPUT);
 pinMode(button, INPUT); 
 digitalWrite (button, LOW);
} 
 
 void loop() 
{ 
  
    if (digitalRead(button) == LOW)

  for(pos = 5; pos < 90; pos += 90)  // goes from 0 degrees to 90 degrees 
  {                                  // in steps of  degree 
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
                          // waits 1s for the servo to reach the position 
  } 
  if (digitalRead(button) == HIGH) 
  
  for(pos = 90; pos>=90; pos-=90)     // goes from 90 degrees to 0 degrees 
  {                                
     myservo.write(pos);              // tell servo to go to position in variable 'pos' 
  delay(5);                             // waits 50ms for the servo to reach the position 
  }
  
}

intramate:
Hi All,

I would like to offer $5 usd to the first person that can add potentiometer adjustment to the code bellow.
Payment will be made via paypal

Currently the code will move a servo horn 90° from a starting position of 5° when a button is pressed. It will also hold the position until the button is released.

What I need is a potentiometer to be able to adjust the value of 90° to a value between 10° - 180°

The code can be posted as a reply, so that anyone can use/see it.

If this is not possible or if I'm too cheap!, please feel free to let me know.
Thanks

#include <Servo.h>

Servo myservo;  // create servo object to control a servo 
// a maximum of eight servo objects can be created 

int pos = 5;    // variable to store the servo position 
int button = 2;  // The button will be on Pin 7 


void setup() 
{ 
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
  pinMode(pos, OUTPUT);
  pinMode(button, INPUT); 
  digitalWrite (button, LOW);
} 

void loop() {
  int destination = map(analogRead(A0), 0,1023, 10, 180);  // fixed typo

  if (digitalRead(button) == LOW) { // Button pushed
    myservo.write(destination);
  } 
  else {
    myservo.write(5);
  }
}

Where's the "pot adjustment" part, John?

Where's the "pot adjustment" part, John?

int destination = map(analogRead(A0, 0,1023, 10, 180));

This will adjust the center. so any other movement should be relevant to this.

I was looking for the pinMode for that.
Pins are Inputs by default, I know, but since there was a pinMode for button I was caught up looking for one for "pot" (nonesuch).

When are there ever pinMode calls for analog pins?

Arrch:

[quote author=Runaway Pancake link=topic=257411.msg1820191#msg1820191 date=1406474898]
I was looking for the pinMode for that.
Pins are Inputs by default, I know, but since there was a pinMode for button I was caught up looking for one for "pot" (nonesuch).

When are there ever pinMode calls for analog pins?
[/quote]
When you want to use an analogPin as digital output...

robtillaart:

Arrch:

[quote author=Runaway Pancake link=topic=257411.msg1820191#msg1820191 date=1406474898]
I was looking for the pinMode for that.
Pins are Inputs by default, I know, but since there was a pinMode for button I was caught up looking for one for "pot" (nonesuch).

When are there ever pinMode calls for analog pins?

When you want to use an analogPin as digital output...
[/quote]

Fair enough. Let's append that statement:

When are there ever pinMode calls for analog input pins?

Arrch:
When are there ever pinMode calls for analog input pins?

I really didn't know that there weren't, that it's unnecessary, and I think that I made that clear.
After a couple of years, I didn't know that analogWrite doesn't require a pinMode call either.
The Reference doesn't note that pinMode calls for analog inputs (vis-a-vis analogRead) are unnecessary.
Technically, a digital input doesn't require a pinMode call either (but there's one up there - and I'm OK with it.)

So, like I said before, already, I went down the rabbit-hole!
Now, if you'll pardon me, I have to go set fire to myself in the backyard.

Hi All,

Thanks to everyone so far for their contribution, especially John.

I have tried to upload the code by John to an Arduino UNO board and I get the following errors;

\arduino-1.0.5-r2\hardware\arduino\cores\arduino/Arduino.h: In function 'void loop()':
\arduino-1.0.5-r2\hardware\arduino\cores\arduino/Arduino.h:101: error: too many arguments to function 'int analogRead(uint8_t)'
test:21: error: at this point in file
\arduino-1.0.5-r2\hardware\arduino\cores\arduino/Arduino.h:209: error: too few arguments to function 'long int map(long int, long int, long int, long int, long int)'
test:21: error: at this point in file

Any help would be appreciated.
Thanks

Just move the close bracket as in this line of John's code.

  int destination = map(analogRead(A0), 0,1023, 10, 180);

Riva:
Just move the close bracket as in this line of John's code.

  int destination = map(analogRead(A0), 0,1023, 10, 180);

Oops. sorry for the typo. Now fixed in the original post.