greetings to all,
I have a project of control of a bionic hand, I already succeeded in controlling 1servomotor with a sensor fsr but to add 4 other motor (dc 12v) and another sensor, I admit that I got lost since I am new in this field, here is the basic code :
#include <Servo.h>
Servo servo;
int reading;
void setup(void) {
Serial.begin(9600);
servo.attach(9); //servo at digital pin 9
servo.write(0); //initial point for servo
}
void loop(void) {
reading = analogRead(A0); //attached to analog 0
Serial.print("Sensor value = ");
Serial.println(reading);
int value = map(reading, 0, 1023, 0, 255);
servo.write(value);
delay(100);
}
Please follow the advice on posting code given in posting code
In particular note the advice to Auto format code in the IDE and to use code tags when posting code here as it prevents some combinations of characters in code being interpreted as HTML commands such as italics, bold or a smiley character, all of which render the code useless
The obvious, but clumsy way, would be to duplicate the code for one servo as many times as you need using different pins and variable names. Have you tried adding 1 more sensor and servo ? Are all 4 extra servos going to behave the same way based on the input from the 1 extra sensor ?
I tried 1 fsr sensor and 2 engines and it works well but as soon as I add the second sensor it blocks (I just copied some code found on the net), I would like to use a FSR to open and the other fsr to close... I specify that I am at my beginnings with arduino.
I've been programming Arduino's for 10 years, and I'm still learning (and always will) new ways to do a task, or perform a function. As a rule, I never use 'copy & paste' code I don't understand. That is, I will sit down and if I can't follow the code just by reading, I will 'flow chart' the code to a diagram, If I get stuck, I'll GOOGLE or ask here or at stack overflow. Being a long time programmer, starting in 1981 with BASIC, COBOL, Assembler, FORTH, C, C++, c# amongst others, there is a lot to be learned from other peoples code. It may take you twice as long to learn, but when you understand the code you are using, you can adapt it, to expand your own knowlege.
missdrew:
I've been programming Arduino's for 10 years, and I'm still learning (and always will) new ways to do a task, or perform a function. As a rule, I never use 'copy & paste' code I don't understand. That is, I will sit down and if I can't follow the code just by reading, I will 'flow chart' the code to a diagram, If I get stuck, I'll GOOGLE or ask here or at stack overflow. Being a long time programmer, starting in 1981 with BASIC, COBOL, Assembler, FORTH, C, C++, c# amongst others, there is a lot to be learned from other peoples code. It may take you twice as long to learn, but when you understand the code you are using, you can adapt it, to expand your own knowlege.
you're absolutely right but I just have a time problem that's why I'm here, thank you for your expertise.
You don't have a time problem, you have a month to learn to skills to do this. If you stick in, it should take you a few hours to work this program out.
Also you say you tried to get 2 working but it blocked. What does this mean, how do you know, can you post your best effort for help.