Arduino is C++, which means it can quite happily compile C code.
Just copy your code there into a new sketch. Add a loop() and setup() function. Add a new tab in the sketch file and call it Motor.h, and paste your motor.h code in there. Press compile and see what happens.
Ok thanks Tom. Actuallty I want to hack a Servo motor and make my own Servo.
Please read my another c code program and tell me the changes to make in that. I attached it as .txt. Please read
That's another one of those "stating the obvious" comments.
I don't know what is a construct.
Get out a dictionary and look up the word. You have constructed a statement that is complete nonsense.
Please tell me how i can convert it in uno 3.
As has been pointed out, the Arduino is programmed using C++, which is a superset of C. There is no conversion required. Although the code that is to be compiled needs to use names that make sense on the Arduino. The code you posted appears to. So, just compile it and see what happens. If there are errors, we can possibly explain them, and help you fix them.
Hahaha this is not homework assignment. I want to make dc servo motor myself. If i use any other code then i have to change the Servo motor controller board.
I attached the motor with Motor Driver and Uno 3. Can you please complete the code below ? I want to add the starting lines. Please define pins.
void setup() {
//Setup Channel A
pinMode(12, OUTPUT); //Initiates Motor Channel A pin
pinMode(9, OUTPUT); //Initiates Brake Channel A pin
}
void loop(){
//forward @ full speed
digitalWrite(12, HIGH); //Establishes forward direction of Channel A
digitalWrite(9, LOW); //Disengage the Brake for Channel A
analogWrite(3, 255); //Spins the motor on Channel A at full speed
delay(3000);
digitalWrite(9, HIGH); //Eengage the Brake for Channel A
delay(1000);
//backward @ half speed
digitalWrite(12, LOW); //Establishes backward direction of Channel A
digitalWrite(9, LOW); //Disengage the Brake for Channel A
analogWrite(3, 123); //Spins the motor on Channel A at half speed
delay(3000);
digitalWrite(9, HIGH); //Eengage the Brake for Channel A
delay(1000);
}
I connected GND to UNO GND
DIR to pin 12
PWM to pin 3 of UNo 3.
Break to pin 8
Your answer seems "yes", but I think you did not get the rhetorical nature of Nick's comment.
(I fear it was not meant to be a yes/no question with free choice of answer)
Well, do you see a problem here?
If "no" is the answer to this question, even after AWOL's hint, you should explain why you need to overload volunteers trying to help you.
( "I'm not a programmer" is no valid excuse, rather a reason to not deal with a µC )