# include <functional> error

I get an error message when running this code

#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Colours.h" 


#include "math.h"
#include <Arduino.h>
#include <functional>

/*
delay should be in millis
*/
static unsigned long _timed_func_last_millis = 0;
template <typename Func, typename... Args>
void timed_func(Func f, unsigned long delay, float step, Args... args) {
    const int  current_millis = millis();
    const unsigned long elapsed = current_millis - _timed_func_last_millis;
    if(elapsed >= delay)
    {
        f((elapsed / delay) * step, args...);
    }
}



static float _shape_orbit_last_step = 0.0;
void shape_orbit(float step, int radius, int sun_x, int sun_y)
{
    step = _shape_orbit_last_step + step;
    step = step - floorf(step);

    _shape_orbit_last_step = step;

    float alpha = PI * 2 * step;

    int moon_x = cos(alpha) * radius + sun_x;
    int moon_y = sin(alpha) * radius + sun_y;

    // YOUR DRAWING FUNCTION
  



}



#ifdef ILI9341DISPLAY

#include "Adafruit_ILI9341.h"
#define TFT_DC 9
#define TFT_CS 10
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);

#else

#include <Adafruit_ST7735.h>
#define TFT_CS        10
#define TFT_RST        8 
#define TFT_DC         7
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);

#endif



void setup() {
#ifdef ILI9341DISPLAY
  tft.begin();
#else
  tft.initR(INITR_BLACKTAB);      // Init ST7735S chip, black tab
  tft.fillScreen(0);
  tft.invertDisplay(false);
  tft.fillScreen(MY_NAVY);
  Serial.println(tft.width());
  Serial.println(tft.height());
  delay(3);
  
#endif
int xcenter = tft.width() / 2;
int ycenter = tft.height() / 2;
int sun_x = xcenter;
int sun_y = ycenter;
int sun_radius = 10;
int radius = 10; 
int moon_radius = 3;

int t_radius = sun_radius + moon_radius + radius;
//int step = 0.7; // should be between 1 and 0 
//int alpha = PI * 2 * step;

//int moon_x = cos(alpha) * t_radius + sun_x;
//int moon_y = sin(alpha)  * t_radius + sun_y;
  



  //tft.fillCircle(xcenter, ycenter, sun_radius, MY_CUSTOM1);
  tft.setCursor(0, 0);
  //tft.fillCircle(moon_x, moon_y, moon_radius, MY_MAROON);
}
  


void loop()
{
    // ** Refill screen
    // ** Draw the sun
int xcenter = tft.width() / 2;
int ycenter = tft.height() / 2;
int sun_x = xcenter;
int sun_y = ycenter;
int sun_radius = 10;
    tft.fillCircle(sun_x, sun_y, sun_radius, MY_CUSTOM1);

    // Drawing moon:
    //tft.fillCircle(moon_x, moon_y, moon_radius, MY_MAROON);
    // timed_func(function, delay, step, radius, sun_x, sun_y);
    timed_func(shape_orbit, 30, 0.02, 10, 50, 50);
    delay(10);
}

this is the error message "C:\Users\0802173\OneDrive - Saskatoon Public Schools\Documents\Arduino\hello\hello.ino:10:10: fatal error: functional: No such file or directory
#include
^~~~~~~~~~~~
compilation terminated.
exit status 1

Compilation error: functional: No such file or directory" I can not figure out what the problem is or how to fix. I am using an arduino uno

This is not a bootloader issue, stk500 issue or avrdude issue. Topic moved to a more suitable location on the forum.

Did you install the 'library' called functional (I have no idea what that library would be, but that is something else)? For which board are you compiling.

It is part of the C++ standard library:

https://en.cppreference.com/w/cpp/header/functional

Thanks.

The C++ Standard Library is not available for Arduino boards (like the Uno) that are based on AVR chips.

The 'timed_func()' template function in that code is only call once. It would be easy enough to rewrite the code without it.

Install this library (availabe in the library manager) and
add #include <ArduinoSTL.h> before #include <functional>.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.