Pages: [1]   Go Down
Author Topic: Quick $5 for the first working response  (Read 1708 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 212
Posts: 8970
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

« Last Edit: July 28, 2014, 06:40:24 am by johnwasser » Logged

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

Offline Offline
Faraday Member
**
Karma: 66
Posts: 2580
Now, More Than Ever
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

"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?"

Shelby Township, Disco, Michigan
Offline Offline
God Member
*****
Karma: 26
Posts: 773
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Where's the "pot adjustment" part, John?
Code:
int destination = map(analogRead(A0, 0,1023, 10, 180));
This will adjust the center. so any other movement should be relevant to this.
Logged

Offline Offline
Faraday Member
**
Karma: 66
Posts: 2580
Now, More Than Ever
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

"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?"

California
Offline Offline
Faraday Member
**
Karma: 92
Posts: 3443
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 224
Posts: 13921
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Rob Tillaart

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

California
Offline Offline
Faraday Member
**
Karma: 92
Posts: 3443
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Offline Offline
Faraday Member
**
Karma: 66
Posts: 2580
Now, More Than Ever
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

"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?"

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
\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
Logged

Norfolk UK
Offline Offline
Faraday Member
**
Karma: 71
Posts: 2601
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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


Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 212
Posts: 8970
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

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

Pages: [1]   Go Up
Jump to: