I'm new in programming arduino....!
Better to say I use only ready sketches..
Now I'm looking for a sketch what I can use as a shifter.
I wanted to use,
1 RC Servo big and strong
1 UNO R3 board
2 push button switches
This will be used to shift the gear of a motorbike 50cc.
The 2 buttons will be used, to switch up and down.
Red button is up,
Green will be down
Those 2 buttons are mounted on the handle bar of the bike, on the left side next to the clutch.
For what I'm looking is,
That when I will press the red button, that the servo will turn to the right side for +- 30°
And when I will press green button, that the servo will turn to the left side for +- 30°
When there is no command of the switches, then the servo must turn to the middle point again.
The + and – of 30° must be variable. Because I don't know how much the servo need to turn.
I guess that it will be a fixed PWM value in the sketch.
Please read the first post in any forum entitled how to use this forum. http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.
What does the variable pos do?
digitalread (pin2,pin3)
This will not read pin2 and pin3, you need separate statements.
Likewise;
if val of (pin2,pin3) = (0,0)
Is not going to accomplish much.
These links might help;
In fact;
might help.
Tom...
PS, Have you tried to compile and run this code?
I am afraid that you are going to have a hard time finding a program to do exactly what you want
There are multiple problems with what you wrote but if you do not understand the basics then it is going to be difficult for you to understand and fix them. You like "ready sketches" so have you worked through the examples in the IDE ?
This I have made...
I did not test yet....
But in Arduino IDE I did not get errors...
What do you think...?
KR
Wolf
#include <Servo.h>
Servo shifter;
int inPin1 = 2;
int inPin2 = 3;
int val = 0;
void setup() {
pinMode(inPin1, INPUT);
pinMode(inPin2, INPUT);
shifter.attach(9);
}
void loop() {
// put your main code here, to run repeatedly:
val = digitalRead(inPin1);
if (val == HIGH) {
shifter.write(120);
}
val = digitalRead(inPin2);
if (val == HIGH) {
shifter.write(60);
}
if (digitalRead(inPin1)==0 && digitalRead(inPin2)==0) {
shifter.write(90);
}
}
If you have not got them in place already I suggest that you add pulldown resistors to keep the inputs in a known state at all times. Better still, use INPUT_PULLUP in the pinModes()s to activate the built in pullup resistors, wire the inputs to go LOW when activated and reverse the logic of your program to match.
if (digitalRead(inPin1)==0 && digitalRead(inPin2)==0)
Better to use LOW rather than 0 for consistency. Or use separate variables for the state of the inputs read earlier in the program and test their values here rather than reading them again.
Incidentally, how is your servo wired ? Where does it get its power from ?