Go Down

Topic: Quick $5 for the first working response (Read 1 time) previous topic - next topic

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

Code: [Select]

#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
  }
 
}


johnwasser

#1
Jul 27, 2014, 02:17 pm Last Edit: Jul 28, 2014, 01:40 pm by johnwasser Reason: 1

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


Code: [Select]

#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);
 }
}

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Runaway Pancake

Where's the "pot adjustment" part, John?
"Hello, I must be going..."
"You gotta fight -- for your right -- to party!"
Don't react - Read.
"Who is like unto the beast? who is able to make war with him?"

steinie44

Quote

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

Code: [Select]

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

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

Runaway Pancake

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).
"Hello, I must be going..."
"You gotta fight -- for your right -- to party!"
Don't react - Read.
"Who is like unto the beast? who is able to make war with him?"

Arrch


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?

robtillaart



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...
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Arrch




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...


Fair enough. Let's append that statement:

When are there ever pinMode calls for analog input pins?

Runaway Pancake


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.
"Hello, I must be going..."
"You gotta fight -- for your right -- to party!"
Don't react - Read.
"Who is like unto the beast? who is able to make war with him?"

intramate

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;

Code: [Select]

\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

Riva

Just move the close bracket as in this line of John's code.
Code: [Select]
  int destination = map(analogRead(A0), 0,1023, 10, 180);

johnwasser


Just move the close bracket as in this line of John's code.
Code: [Select]
  int destination = map(analogRead(A0), 0,1023, 10, 180);


Oops.  sorry for the typo.  Now fixed in the original post.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Go Up