I have a program that was written in ".C" is there a way to convert it so that I can use it with the Arduino program?
variable definitions, logic and flow control statements etc tend to be similar from system to system
- memory allocated to variables may change, e.g. ints may be 16, 32 or 64 bits in size
- in the case of the arduino the IO system is different, e.g. rather than printf() statements use Serial.print() statements
- some of the #include <> files may be different from standard c/C++
At the very least you will need to add a setup() and loop() function and move the appropriate code or calls to your existing functions into those two functions. There are ways to avoid doing this by using the main() function but you will then need to make changes such that the Arduino init() function is called to set up hardware and you will also need to #include Arduino.h
Input and output will need to be changed to use Arduino functions.
All in all it may be easier to write the program from scratch.
What does the C program do ?
Thank you for the quick response.
This program will control a VL6180x it is controled by a 32u4 chip. I am using this time of flight sensor to measure a range at different points on a plate, it will be a oneshot read, wait for reset and read again, after every button push the range will be read and recorded.
At least thats what I want it to do.....
what system was the original code written on?
the I2C library to communicate with the VL6180x will probably have different function names etc but all I2C libraries do the same thing, e.g. initialisation, send/receive, etc
it is a Feather board from Adafruit, its perfect for this job as it is small enough to fit in the area I need. the i2c librarys work well and I have it working with the examples provided by adafruit , however the api has all its examples written in "c" some of the programs in the api are what I am trying to use different parts, I will say that as a C programmer I am no good , now if it was a PLC or a CNC then I would not have to much of an issue but c is a little confusing, the Arduino program is great for working with these small chips but again not my best area.
UKHeliBob:
At the very least you will need to add a setup() and loop() function
Setup and Loop can be avoided by doing this instead:
int main (void)
{
init(); // run Arduino init()
Serial.begin (115200); // if you need the serial port
//
// all your code goes here
//
while (1); // hang here when done - code has nowhere to "return" to
}