Search code examples
c++carduinoesp8266arduino-esp8266

How to use pinout with esp8266 from C file?


I have a very basic example of the task I'm trying to solve. From the main loop in arduino.ino I call the sample_run() function in device.c using the definition in sample.h. From here I'm trying to understand how I can use the GPIO pins from device.c. Can this be done using the arduino ide? I've attached some sample code of what I'm trying to do.

arduino.ino

#include "sample.h"
#include "esp8266/sample_init.h"

void setup() {
}

void loop() {
  sample_run();
}

sample.h

#ifndef SAMPLE_H
#define SAMPLE_H

#ifdef __cplusplus
extern "C" {
#endif

    void sample_run(void);

#ifdef __cplusplus
}
#endif

#endif /* SAMPLE_H */

device.c

#include "sample.h"
void sample_run(void)
{
    //I would like to turn on/off led here
}

Solution

  • In device.c: #include "Arduino.h"

    Why are you using .c files and not .cpp?