hello all, ive been looking at how to do this and I have come up with the following code. I am sorry I am a complete novice with Arduino and this will probably be easy for some here to work out.
I'm trying to control the inmoov hand with an ir remote. I know there are ways of controlling the hand with myrobot labs but this hand is a gift for a friends son and it needs to be stand alone.
I can get one button on the remote to control one finger but I cannot figure out how or what to write to get the other fingers to move with other buttons. I may be missing something blindingly obvious but as I have said I am a complete novice and I'm surprised ive got this far.
I hope someone can help me and thanks in advance
#include <IRremote.h> //must copy IRremote library to arduino libraries
#include <Servo.h>
#define thumb1 0xFFA25D //clockwise rotation button
#define thumb2 0xFF22DD//counter clockwise rotation button
int RECV_PIN = 2; //IR receiver pin
Servo servo;
int val; //rotation angle
bool cwRotation, ccwRotation; //the states of rotation
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
servo.attach(3); //servo pin
}
void loop()
{
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value
if (results.value == thumb1)
{
cwRotation = !cwRotation; //toggle the rotation value
ccwRotation = false; //no rotation in this direction
}
if (results.value == thumb2)
{
ccwRotation = !ccwRotation; //toggle the rotation value
cwRotation = false; //no rotation in this direction
}
}
if (cwRotation && (val != 160)) {
val++; //for colockwise button
}
if (ccwRotation && (val != 0)) {
val--; //for counter colockwise button
}
servo.write(val);
delay(05); //General speed
}
Yeah I understand all about common grounds I used to be an auto electriction and now I build wire harness's I just wanted to keep this simple until the final build. Using a prototype pcb to build a custom adaptor for the servo plugs and hide that inside the arm/hand.
How ever this still hasn't helped me with the programming.
like I said I am a complete novice with code. ask me to 3d print some thing and I can work wonders but this is rather daunting.
thumb1 is one button moves the thumb forward
while thumb2 does the opposite with a different button on the remote.
problem is theres not enough code for the other fingers and I don't know how to put that code in or if I can use the code I already have and add to it ?
my apologise when I said come up with this code i didn't mean to imply i wrote it my bad i should have been a little clearer. I do appreciate the help but where wold I put what you've just written ? could you do a small example ?
To have more servos, you need more servo instances in your sketch, one for each digit.
I think you should step back and go through the servo example until you fully understand the nuances.
Have you studied:
Servo questions have been dealt with many times here.
There is a search feature at the top of the screen.
Search for 'multiple servos'.
So hopefully you are an expert in robotics and controlling multi-axis robots.
Hint: The code you posted above just declares one Servo object and attaches it to a single Arduino pin.
If you want to control several Servos, then you better declare as many Servo objects in your code as you want to control and attach a pin to each of them!