Servo language question

Hi,
Just use a potentiometer, then you can have 1024 levels of adjustment, if thats still too many, still use a potentiometer but divide its value by 256 to get 4 levels of adjustment or 128 to get 8 different periods.

to get 1024 values -

int nPeriod = analogRead(POT_PIN); // nPeriod = 0 to 1024
nPeriod *= 10; // nPeriod is multiplied by 10 so now give a period from 0 to 10240 milliseconds (10.2 seconds)

if you just want to adjust between 4 fixed values -

int nSetting = analogRead(POT_PIN); // nSetting = 0 to 1024
nSetting >> 8; // divide by 256 nSetting = 0 to 3;

int nPeriod = 0;

switch(nSetting)
{
case 0:
    nPeriod = 3000; // 3 seconds
    break; 
...
...
case 3:
    nPeriod = 25000; // 12 seconds
    break; 
}

Duane B

bren21m:
i want to be able to change the amout of time inbetweeen wipes with a 3 point switch like i said in my original question

In that case both those 'for' loops are a waste of time. You just need to send the servo its new position and then wait for the required interval before moving it back. But instead of a fixed delay (8000) you will delay by an amount held in a variable, which you set based on the value read from your switch. For three distinct positions (or perhaps four, if you want an 'off' position) I'd use a rotary switch with different resistors at each position set up to act as a voltage divider, use an analog input to read the voltage and do a range comparison to decide which position the switch is in, use that as an index into an array of delay values.

would one like this be ok?

hi everyone,

im going to go with the potentiometer idea idea and i bought this one

i really have no idea where to start with writing the program to use it so you could have told me already and i wouldnt know it.

i wanted to know if somone would be nice enough to write it and then explain how you did it. i would really appreciate it. i would also like to know which pin on the potentiometer goes to which pin on the arduino board and if there has to be another 5 volts going to the potentiometer like the servo.

thankss,

Brendan

ok so i now know how the potentiometer works there are 2 pins in the middle on the bottom and 12 around the edge. the one pin controls the 6 on that side and the other pin controls the 6 pins on the other side. when you turn the knob it in snaps into a position and what ever electricity is comming thruogh the pin goes out that outer pin on that side only and if there is any electricity is in the other pin it goes through to that sides pin. so now i need to know which pin hole on the adruino board i connect to the 6 pins on the one side on the potentiometer.. the other 6 will most likely be LEDs showing which position it is in. and i also need to figure out how to program the arduino (so that when pin #X on the arduino gets electricity then make the delay 5000) etc

im pretty sure thats what i have to do. correct me if im wrong. im only 15

i have the arduino UNO if that helps anything

im going to go with the potentiometer idea idea and i bought this one

That is not a pot, it is a switch.

That is not a pot, it is a switch.

After enough pot, it could be... 8)

ohh, well is that how my switch workss?

i want the program on the arduino to say, when positiion 1 on the switch gets a signal in whatever pin it goes in on the arduino to make the delay this many milliseconds and so on. does anyone know what pins should be used for the switch i got?

Two servo test code that can be modified to position a single servo in several different positions depending on the switch position.

//zoomkat servo button test 12-29-2011

#include <Servo.h>
int button1 = 4; //button pin, connect to ground to move servo
int press1 = 0;
int button2 = 5; //button pin, connect to ground to move servo
int press2 = 0;
Servo servo1;

void setup()
{
  pinMode(button1, INPUT);
  pinMode(button2, INPUT);
  servo1.attach(7);
  digitalWrite(4, HIGH); //enable pullups to make pin high
  digitalWrite(5, HIGH); //enable pullups to make pin high
}

void loop()
{
  press1 = digitalRead(button1);
  if (press1 == LOW)
  {
    servo1.write(170);
  }    
  
  press2 = digitalRead(button2);
  if (press2 == LOW)
  {
    servo1.write(10);
  }
  
  /*else {
    servo1.write(90);
  }*/
}

that wouldn't adjust the delay for each switch postion would it? or i would have to chanfe it to do that?

would a video explaining help? im a beginner so if you guys already put it in black and white please show me. i have no idea where to start, im not impatient its just people are annoying me to finish it, so id like toget it done soon. thanks

i have no idea where to start, im not impatient its just people are annoying me to finish it, so id like toget it done soon. thanks

Sounds like a school assignment. So what have you tried on your own since your last post on July 19?

i tried to see if i could find anything like a diagram or somthing on google showing how to connect the switch to the arduino but i couldnt find anything. i also looked to see if anyone did Anything similar to what im doing but i couldnt find anything i also made this video a few day ago scince i dont have my gopro at the moment.

i know it can be a whole lot better. but thats just the way i am with everything. its also ok for my first video like that.

bren21m:
i also made this video a few day ago scince i dont have my gopro at the moment.

What the bleep has that video got to do with your question?

PeterH:

bren21m:
i also made this video a few day ago scince i dont have my gopro at the moment.

What the bleep has that video got to do with your question?

It is what you do while waiting for somebody to do your homework for you. :slight_smile:

lol, no i made that video the other day because the camera im making this wiper for is getting fixed. and it not my home work, my dad is nagging my to make it and all these people want me to make them it. they think i can just turn it out. like no i have no idea where to start i used a code that came with the program. this is the camera i use the wiper on. its a gopro

you can see the wiper go like every 8 or 10 seconds i forget what i set it too

if you think a video would help ill make one.
and im only 16 so i wouldnt have a class that would expect me to build somthing like this and it is summer.

zoomkat:
Two servo test code that can be modified to position a single servo in several different positions depending on the switch position.

//zoomkat servo button test 12-29-2011

#include <Servo.h>
int button1 = 4; //button pin, connect to ground to move servo
int press1 = 0;
int button2 = 5; //button pin, connect to ground to move servo
int press2 = 0;
Servo servo1;

void setup()
{
  pinMode(button1, INPUT);
  pinMode(button2, INPUT);
  servo1.attach(7);
  digitalWrite(4, HIGH); //enable pullups to make pin high
  digitalWrite(5, HIGH); //enable pullups to make pin high
}

void loop()
{
  press1 = digitalRead(button1);
  if (press1 == LOW)
  {
    servo1.write(170);
  }   
 
  press2 = digitalRead(button2);
  if (press2 == LOW)
  {
    servo1.write(10);
  }
 
  /else {
    servo1.write(90);
  }
/
}

im pretty sure this would work its just i dont know how and where to insert it into my code to make it not change the position of the servo but change the delays and what pins on the arduino to connect the the pins on the switch
also can i just solder the servo positive to the positive on the switch to one pin and put that pin in the 5v on the arduino or would i need to get one of those breadboards that are like white plastic

i made this video a while back then just stopped caring about gettingthe wiper done because race season was over, but now its possible we are going to have a race in mid febuary so i figured i would get it done now, i hope this clearly explains my question

i know i sound like a dweeb, i was sick.