Hi I need some help here. What's the differences between the Arduino and C programming, in term of their purpose, programme structure, and code syntax? I just started learning Arduino code for blinking LED but how do I modify it to C programming? The LED turns on for 2400 ms and turns off for 1600 ms. I want to get some expert's opinion and not just ai.
I moved your topic to an appropriate forum category @98jijutsu .
In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.
This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.
Thanks in advance for your cooperation.
Is this some kind of homework assignment?
Anyway, did you check arduino website?
The Arduino IDE programming environment is C++ with extensions to allow the Arduino hardware to be controlled
... and a few limitations
- depending on the target MCU.
Yeah, I already submitted it but I need some clarification. Yes, I've checked the website.
So you mean the purpose of Arduino is to control a hardware?
So you mean the purpose of Arduino is to control a hardware?
you need to post the code ??
Oh sorry I read it wrong lol
What do you want to modify? Arduino sketches are written in C++ ( not pure C ). There are some hidden parts (e.g. main() ) to make it easier for beginners. You can write the main() function by yourself if you want to. But then you have to dig deeper into the Arduino core code. It does a lot of basic things for you - e.g. initializing the HW of the MCU - if you let it do its job.
Most ANSI/ISO Standard C/C++ won't run on the Arduino (at least without modification) because C/C++ expects an operating system, file system, standard display, and standard keyboard. .i.e. The classic-standard "Hello World" won't work.
And, there's no way to read an I/O port or blink an LED with standard C/C++. Those hardware-specific things require special-additional libraries.
not true. i've developed lots of code on my laptop that runs fine on Arduino. The Arduino IDE use uses the industry standard GNU C++ compiler
of course, you can't execute code that actual drives a motor or controls other hardware on or connected to an Ardiuno on a laptop, by you can use prints to show what the arguments to such functions are.
This comes up every once in a while.
I think it is useful to differentiate between a language, and a language plus the context it is found in.
Many modern languages simply would not run on microprocessors, they are huge. In and of themsleves, I would say it would be like making the STL an actual part of the C++ language.
Modern language texts often start with a few chapters that are essentially all of C.
So Arduino is programmed in C++. Period. It is made easier by all the junk that comes out of the box with the IDE, and further so by the thousands of libraries for doing anything you might think of, almost.
Big rigs can be programmed in C or C++; usually there is a bunch of junk sitting around that doing so depends on.
For microprocessors that aren't as beefy as, say, the UNO, C has become a good fit with the modern compilers, and the heavies who thought it would never be so now have fewer things that actually need assembly language.
a7
I am an expert at being a novice. At no time have I ever, knowingly, programmed in C++. It matters not to expert novices like me, that all the code I will ever write is supported by libraries using C++.
In the same vein, I do not speak German because I get "cranky," nor Italian because I order Pizza from the shop around the corner (ham and artichoke or spinach and garlic... venti minuti).
Knowing this little about the insides of programming languages has its benefit: I do not lose sleep when C/C++ wars start.
Program in C and learn to use the "mute" preference.
Mmm… pizza.
a7
I always thought of C as the programming version of Latin. It the base for bloody near everything. c++ is kinda' like english. Closer to a modern language, Depends a lot on the accent/dialect you speak with. People are still futzing around with it.
-jim lee
LISP. LISP is the classic greek of programming languages. Nobody ever heard of Latin. Or C. Or C++. Or PHP ...
... now let the carnage begin ...
Arduino code for blink:
void loop() {
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
}
C code for blink (using avr-libc):
int main() {
while (1) {
PORTB |= 1<<PINB5;
_delay_ms(1000);
PORTB &= ~(1<<PINB5);
_delay_ms(1000);
}
}
C is complete but no frills. It's been described as a high level assembler.
It was co-developed with Unix which was orignally written in assembler and C written to be able to access the hardware no other language was capable of doing.
C++ was originally implemented as a translator converting C++ into C. So C was capable of doing was C++ was capable of. Fortran was also originally implemented on Unix as a translator into C.
C++ has been described as having more "guard rails" than C
