Libraries elimination

Hello everyone I am new to Arduino and I need some help over here… so, I have this project at school and our mentors told us that we can use Arduino but we can’t use libraries. I found this program online just as a clue to help me out but it has libraries. Can somebody help me out to remove the libraries please? Specifically the <servo.h> , THE PROJECT IS AN ANIMATRONIC HAND! - link -

I appreciate any help. Thanks :slight_smile:

Below is the Program.

#include <Servo.h> //Includes servo library

Servo finger1, finger2, finger3, finger4, finger5;

int servoPin1 = 5;
int servoPin2 = 6;
int servoPin3 = 9;
int servoPin4 = 10;
int servoPin5 = 3;

int flexPin1 = A0;
int flexPin2 = A1;
int flexPin3 = A2;
int flexPin4 = A3;
int flexPin5 = A4;

void setup()
{
 //Attach the servo objects to their respective pins
 finger1.attach(servoPin1);
 finger2.attach(servoPin2);
 finger3.attach(servoPin3);
 finger4.attach(servoPin4);
 finger5.attach(servoPin5);
 
 /* set each servo pin to output; I'm not acutally sure if this is
 even necessary, but I did just in case it is */
 pinMode(servoPin1, OUTPUT);
 pinMode(servoPin2, OUTPUT);
 pinMode(servoPin3, OUTPUT);
 pinMode(servoPin4, OUTPUT);
 pinMode(servoPin5, OUTPUT);
 
 //Set each flex sensor pin to input: this is necessary
 pinMode(flexPin1, INPUT);
 pinMode(flexPin2, INPUT);
 pinMode(flexPin3, INPUT);
 pinMode(flexPin4, INPUT);
 pinMode(flexPin5, INPUT);
 
 
}

void loop()
{
 //Defines analog input variables
 int flex1 = analogRead(flexPin1);
 int flex2 = analogRead(flexPin2);
 int flex3 = analogRead(flexPin3);
 int flex4 = analogRead(flexPin4);
 int flex5 = analogRead(flexPin5);
 
 /* Defines "pos" variables as being proportional to the flex inputs.
 The 400 to 700 value range seemed adequate for my sensors, but you can change
 yours accordingly. */
 int pos1 = map(flex1, 400, 700, 0, 180);
 pos1 = constrain(pos1, 0, 180);
 int pos2 = map(flex2, 400, 700, 0, 180);
 pos2 = constrain(pos2, 0, 180);
 int pos3 = map(flex3, 400, 700, 0, 180);
 pos3 = constrain(pos3, 0, 180);
 int pos4 = map(flex4, 480, 640, 0, 180);
 pos4 = constrain(pos4, 0, 180);
 int pos5 = map(flex5, 400, 700, 0, 180);
 pos5 = constrain(pos5, 0, 180);
 
 //Tells servos to move by the amount specified in the "pos" variables
 finger1.write(pos1);
 finger2.write(pos2);
 finger3.write(pos3);
 finger4.write(pos4);
 finger5.write(pos5);
}

Please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum

I reckon you need to give us the exact project specification as set by your mentors.

Of course you can write code that is equivalent to the Servo library - but why would you?

…R

Of course you can write code that is equivalent to the Servo library - but why would you?

Ever heard of "project specification" ? >:(
Can you stay on the subject?

Your code is about three times as long as it needs to be.

Why do you want to eliminate something that makes your task easier?

Also, DO NOT CROSS-POST.

CROSS-POSTING WASTES TIME.

Duplicate deleted.

There could be many reasons for disallowing libraries. Ease or uniformity of grading. The instructor doesn't have to learn the multiple libraries that students dig up. Forcing the students to concentrate on basics. Perhaps others.

If I were teaching the course and this were a problem, I would either:

  1. Provide a limited package of libraries keyed to the assignment, no others allowed.

or

  1. Limit the nature of the assignment to tasks that can be easily achieved without a library. "animatronic hand" just doesn't seem like that. :slight_smile:

and

  1. Ask students to write a library (last half of the course). Separate the code that you have already written, moving the low level functions into your new library. Or a more simple task, like adding a new function to an existing (instructor provided) library.

aarg:
There could be many reasons for disallowing libraries. Ease or uniformity of grading. The instructor doesn't have to learn the multiple libraries that students dig up. Forcing the students to concentrate on basics. Perhaps others.

If I were teaching the course and this were a problem, I would either:

  1. Provide a limited package of libraries keyed to the assignment, no others allowed.

or

  1. Limit the nature of the assignment to tasks that can be easily achieved without a library. "animatronic hand" just doesn't seem like that. :slight_smile:

and

  1. Ask students to write a library (last half of the course). Separate the code that you have already written, moving the low level functions into your new library. Or a more simple task, like adding a new function to an existing (instructor provided) library.

aarg:
There could be many reasons for disallowing libraries. Ease or uniformity of grading. The instructor doesn't have to learn the multiple libraries that students dig up. Forcing the students to concentrate on basics. Perhaps others.

If I were teaching the course and this were a problem, I would either:

  1. Provide a limited package of libraries keyed to the assignment, no others allowed.

or

  1. Limit the nature of the assignment to tasks that can be easily achieved without a library. "animatronic hand" just doesn't seem like that. :slight_smile:

and

  1. Ask students to write a library (last half of the course). Separate the code that you have already written, moving the low level functions into your new library. Or a more simple task, like adding a new function to an existing (instructor provided) library.

Some valid, but...

I would sincerely hope "mentors" already explained that C language ( and many others) is extendible (sic?) and while at that steered away from Arduino's incorrect usage of term "library".
That would in the long run teach concepts instead of making it easier for "uniform" grading.

And yes - another "I want to shoot a rocket ( artificial hand ) to the Moon but cannot be bothered to learn how to code and / or write meaningful comments."

" It's not easy being green or a teacher " to quote Kermit the frog. or

" It's not easy being green or a teacher "

Take your pick.

And I still do not know why when I use SINGLE click "Quote" I get two of them.
Tired of fixing it - dear moderators.

Vaclav:
Ever heard of "project specification" ? >:(
Can you stay on the subject?

If you read my Reply #1 carefully you would have noticed that I asked for the project specification BEFORE I made the comment you seem to have taken exception to.

@Josmt, for me "THE PROJECT IS AN ANIMATRONIC HAND" is the title of the project - not the specification. Please provide all the details of the specification.

I agree with @aarg that it seems very strange to propose a complex project like that and not allow the use of libraries. In any case, virtually the first thing you would have to do is create the equivalent of the servo library. It would be a real bird's nest code that did not do that.

...R

Josmt:
Can someone at least try and help me do that program to a non library one ?

I'm quite uncomfortable with this. You don't seem to have done any analysis of your project to see just what you need to study. You just seem to have thrown you hands in up in the air and decided that you do not want to learn anything so you will try to get others to do the work for you. You don't even seem to have looked at the source code of the library you are not allowed to use directly!

It is your project and members of this forum will assist but YOU have to show some effort.

Josmt:
Can someone at least try and help me do that program to a non library one ?

You have already been advised (more than once, I think) that you need to write some code that does the same job as the servo library.

Have you researched how servos are controlled - it is not very complex. There is plenty of advice on the web already. It would be a complete waste of my time to write another essay on the same subject.

...R

Our mentors told us that we can use Arduino but we can’t use libraries.

Better check whether that means you can’t use ANY arduino libraries (including the core.)
It wouldn’t be too unreasonable to allow use of the arduino hardware, but want you to write all the code in
bare C.

westfw:
Better check whether that means you can't use ANY arduino libraries (including the core.)
It wouldn't be too unreasonable to allow use of the arduino hardware, but want you to write all the code in
bare C.

I agree. But the OP has so far ignored my requests to see the detailed project specification where this might be made clear.

...R

Robin2:
I agree. But the OP has so far ignored my requests to see the detailed project specification where this might be made clear.

...R

That reminds me. If it was my course, I would require that this be submitted along with the code. No spec, no marks.

Josmt:
Hello everyone I am new to Arduino and I need some help over here… so, I have this project at school and our mentors told us that we can use Arduino but we can’t use libraries. I found this program online just as a clue to help me out but it has libraries. Can somebody help me out to remove the libraries please? Specifically the <servo.h> , THE PROJECT IS AN ANIMATRONIC HAND! - link -

Animatronic Hand - YouTube

I appreciate any help. Thanks :slight_smile:

Below is the Program.

#include <Servo.h> //Includes servo library

Servo finger1, finger2, finger3, finger4, finger5;

int servoPin1 = 5;
int servoPin2 = 6;
int servoPin3 = 9;
int servoPin4 = 10;
int servoPin5 = 3;

int flexPin1 = A0;
int flexPin2 = A1;
int flexPin3 = A2;
int flexPin4 = A3;
int flexPin5 = A4;

void setup()
{
//Attach the servo objects to their respective pins
finger1.attach(servoPin1);
finger2.attach(servoPin2);
finger3.attach(servoPin3);
finger4.attach(servoPin4);
finger5.attach(servoPin5);

/* set each servo pin to output; I’m not acutally sure if this is
even necessary, but I did just in case it is */
pinMode(servoPin1, OUTPUT);
pinMode(servoPin2, OUTPUT);
pinMode(servoPin3, OUTPUT);
pinMode(servoPin4, OUTPUT);
pinMode(servoPin5, OUTPUT);

//Set each flex sensor pin to input: this is necessary
pinMode(flexPin1, INPUT);
pinMode(flexPin2, INPUT);
pinMode(flexPin3, INPUT);
pinMode(flexPin4, INPUT);
pinMode(flexPin5, INPUT);

}

void loop()
{
//Defines analog input variables
int flex1 = analogRead(flexPin1);
int flex2 = analogRead(flexPin2);
int flex3 = analogRead(flexPin3);
int flex4 = analogRead(flexPin4);
int flex5 = analogRead(flexPin5);

/* Defines “pos” variables as being proportional to the flex inputs.
The 400 to 700 value range seemed adequate for my sensors, but you can change
yours accordingly. */
int pos1 = map(flex1, 400, 700, 0, 180);
pos1 = constrain(pos1, 0, 180);
int pos2 = map(flex2, 400, 700, 0, 180);
pos2 = constrain(pos2, 0, 180);
int pos3 = map(flex3, 400, 700, 0, 180);
pos3 = constrain(pos3, 0, 180);
int pos4 = map(flex4, 480, 640, 0, 180);
pos4 = constrain(pos4, 0, 180);
int pos5 = map(flex5, 400, 700, 0, 180);
pos5 = constrain(pos5, 0, 180);

//Tells servos to move by the amount specified in the “pos” variables
finger1.write(pos1);
finger2.write(pos2);
finger3.write(pos3);
finger4.write(pos4);
finger5.write(pos5);
}

You seems to have misconception about this forum.
It is not a substitute for teaching how to code.
Just read the forum description.

Most contributors here do not mind lending a helping hand, give hits , point to “problem” in code etc.

You are asking this group , very directly, to do your schoolwork for you.

Just to borrow from anther coding forum " how to post a question " - “don’t you forget that your teacher MAY be reading your posts” .

In short - no pain , no gain.

Enough said

westfw:
Better check whether that means you can’t use ANY arduino libraries (including the core.)

Yes, better check. I imagine that you can can actually use libraries for basic functions, including servos, sensors.
But they just want to prevent that you …

#include <RobotHand.h>
...
myHand.doStuff();

Jobi-Wan:

#include <RobotHand.h>


myHand.doStuff();

LOL

I guess that is what @PaulS means when he says “stop the hand waggling”
(hope I am not misquoting too much)

…R