0

I need to convert Arduino code to avr-gcc code. This is code:

#include <Servo.h> 

Servo myservo; 

void setup() {
  myservo.attach(11);
}

void loop() { 
  myservo.write(67);
}

I use Arduino Mega.

closed as off-topic by Majenko, Gerben, Mattia, sa_leinad, Paul Jan 14 '17 at 9:17

  • This question does not appear to be about Arduino, within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 4
    I'm voting to close this question as off-topic because this is not a "gimme tha codez" site. – Majenko Jan 13 '17 at 13:38
  • Possible duplicate of Will a .ino Arduino Sketch compile directly on GCC-AVR? – sa_leinad Jan 14 '17 at 3:57
  • 1
    You didn't actually ask a question, you might have asked: "how can I re-implement the servo library in avr-gcc", but that will require quite some effort and a little knowledge from your side. – Paul Jan 14 '17 at 9:22
3

Try this:

#include <Servo.h>

extern "C" void init(void);

Servo myservo;

int main()
{
    init();
    myservo.attach(11);
    for (;;) {
        myservo.write(67);
    }
}

Note that this still needs the Arduino core library, as the Servo library depends on it, which means all this is an exercise in futility. If you are using the Arduino core, the simplest thing is to use it the Arduino way. If you do not want to use Arduino core, then you will have to partially re-implement the Servo library.

  • @user29971: oops, forgot an include, fixed. Do not forget to add all the relevant -I, -L and -l options to the compile command. – Edgar Bonet Jan 13 '17 at 14:02
  • compiler code in avr-gcc comand line in linux no include Arduino.h include avr/io.h. thanks Edgar Bonet – user29971 Jan 13 '17 at 14:07
  • i use standard library and registers. – user29971 Jan 13 '17 at 14:15
  • @user29971: If you do not want to #include <Arduino.h>, you can just declare init() yourself, see amended answer. – Edgar Bonet Jan 14 '17 at 8:05

Not the answer you're looking for? Browse other questions tagged or ask your own question.