Arduino Code Error (Firefly Generated)

Hello, I am a newbie to Arduino. So happy to be on this forum between you intellectual people. Below is my arduino code generated by Firefly (Rhino Grasshopper Plugin). When I try to upload it to my board it generates series of errors. Can somebody please look into the matter and guide me to the correct path :slight_smile:

/*
Firefly Code Generator by Andy Payne
Copyright 2011 All Rights Reserved
Code Generated on 07/30/2021 12:38:09
Special thanks to Panagiotis Michalatos.
For more information visit: www.fireflyexperiments.com
*/

#include "FFCasts.h"
#include <Servo.h>

//******************* Begin Function Definitions *******************

//Remap Number Function: Remap a value into a new numeric domain.
double Remap_Numbers(double x, Interval _in, Interval _out) {
  return (x - _in.t0) * (_out.t1 - _out.t0) / (_in.t1 - _in.t0) + _out.t0;
}

//Multiplication Function: Multiply two numbers.
inline double Multiplication(double _v1, double _v2){
  return _v1 * _v2;
}

//Constrain Function: Constrains a number to a specific numeric range.
double Constrain(double _v1, Interval _in){
  double _min, _max, result;
  if (_in.t0 < _in.t1){
    _min = _in.t0;
    _max = _in.t1;
  }else{
    _min = _in.t1;
    _max = _in.t0;
  }
  if (_v1 < _min){
    result = _min;
  }else if (_v1 > _max){
    result = _max;
  }else{
    result = _v1;
  }return result;
}

double smoothlist_0[1];
int smoothindex_0 = 0;
double smoothtotal_0 = 0.0;

//Smoothing Function: Smooth (or average) an incoming value based on (N) number of samples.
double Smoothing_Moving_Average(double _v1, int _n, double *_list, int *_index, double *_total){
  *_total -= _list[*_index];
  *_total += _v1;
  _list[*_index] = _v1;
  (*_index)++;
  if (*_index >= _n) *_index = 0;
  return *_total/(double)_n;
}

//******************** End Function Definitions ********************

Servo servo-1;

void setup() {
  int smi;
  for(smi = 0; smi < 1; ++smi) {
    smoothlist_0[smi] = 0.0;
  }
  servo-1.attach(-1);
}

void loop() {
  digitalWrite(-1, Multiplication(Remap_Numbers(Analog_Pin_0,Interval(100,250),Interval(1,0)),0));
  digitalWrite(-1, Multiplication(Remap_Numbers(Analog_Pin_0,Interval(100,250),Interval(0,1)),0));
  servo-1.write(Smoothing_Moving_Average(Remap_Numbers(Constrain(Analog_Pin_0,Interval(100,250)),Interval(100,250),Interval(85,99)),1, smoothlist_0, &smoothindex_0, &smoothtotal_0));
}



struct Interval {
	Interval(double _t0, double _t1) {
		t0=_t0;
		t1=_t1;
	}

	Interval(double _t1) {
		t0=0.0;
		t1=_t1;
	}

	Interval(const Interval &_i) {
		t0=_i.t0;
		t1=_i.t1;
	}


	double t0, t1;
};

Errors


Arduino: 1.8.15 (Windows Store 1.8.49.0) (Windows 10), Board: "Arduino Uno"

Firefly:59:12: error: expected initializer before '-' token

 Servo servo-1;

            ^

D:\SCET\Academics\5th Year\Research\Firefly\Firefly.ino: In function 'void setup()':

Firefly:66:3: error: 'servo' was not declared in this scope

   servo-1.attach(-1);

   ^~~~~

D:\SCET\Academics\5th Year\Research\Firefly\Firefly.ino:66:3: note: suggested alternative: 'Servo'

   servo-1.attach(-1);

   ^~~~~

   Servo

Firefly:66:9: error: unable to find numeric literal operator 'operator""attach'

   servo-1.attach(-1);

         ^~~~~~~~

D:\SCET\Academics\5th Year\Research\Firefly\Firefly.ino: In function 'void loop()':

Firefly:70:49: error: 'Analog_Pin_0' was not declared in this scope

   digitalWrite(-1, Multiplication(Remap_Numbers(Analog_Pin_0,Interval(100,250),Interval(1,0)),0));

                                                 ^~~~~~~~~~~~

D:\SCET\Academics\5th Year\Research\Firefly\Firefly.ino:70:49: note: suggested alternative: 'analogWrite'

   digitalWrite(-1, Multiplication(Remap_Numbers(Analog_Pin_0,Interval(100,250),Interval(1,0)),0));

                                                 ^~~~~~~~~~~~

                                                 analogWrite

Firefly:72:3: error: 'servo' was not declared in this scope

   servo-1.write(Smoothing_Moving_Average(Remap_Numbers(Constrain(Analog_Pin_0,Interval(100,250)),Interval(100,250),Interval(85,99)),1, smoothlist_0, &smoothindex_0, &smoothtotal_0));

   ^~~~~

D:\SCET\Academics\5th Year\Research\Firefly\Firefly.ino:72:3: note: suggested alternative: 'Servo'

   servo-1.write(Smoothing_Moving_Average(Remap_Numbers(Constrain(Analog_Pin_0,Interval(100,250)),Interval(100,250),Interval(85,99)),1, smoothlist_0, &smoothindex_0, &smoothtotal_0));

   ^~~~~

   Servo

Firefly:72:9: error: unable to find numeric literal operator 'operator""write'

   servo-1.write(Smoothing_Moving_Average(Remap_Numbers(Constrain(Analog_Pin_0,Interval(100,250)),Interval(100,250),Interval(85,99)),1, smoothlist_0, &smoothindex_0, &smoothtotal_0));

         ^~~~~~~

Multiple libraries were found for "Servo.h"

 Used: C:\Users\Dell\Documents\Arduino\libraries\Servo

 Not used: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\libraries\Servo

exit status 1

expected initializer before '-' token


This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

you can't use the minus-sign or a dot in names if you want spacing use the underline sign.

1 Like

May you please exactly pin-point out where am I going wrong. It's just been a day or two since I started learning these.

the compiler quotes the line (72) and the columm (9) where the error occurred.
So search through the errormessages to find them all.

1 Like

Thank you so much for the response. I tried running your solution and it is getting closer to solve.

Here is the new script and the errors!

/*
Firefly Code Generator by Andy Payne
Copyright 2011 All Rights Reserved
Code Generated on 07/30/2021 12:54:33
Special thanks to Panagiotis Michalatos.
For more information visit: www.fireflyexperiments.com
*/

#include "FFCasts.h"
#include <Servo.h>

//******************* Begin Function Definitions *******************

//Remap Number Function: Remap a value into a new numeric domain.
double Remap_Numbers(double x, Interval _in, Interval _out) {
  return (x - _in.t0) * (_out.t1 - _out.t0) / (_in.t1 - _in.t0) + _out.t0;
}

//Multiplication Function: Multiply two numbers.
inline double Multiplication(double _v1, double _v2){
  return _v1 * _v2;
}

//Constrain Function: Constrains a number to a specific numeric range.
double Constrain(double _v1, Interval _in){
  double _min, _max, result;
  if (_in.t0 < _in.t1){
    _min = _in.t0;
    _max = _in.t1;
  }else{
    _min = _in.t1;
    _max = _in.t0;
  }
  if (_v1 < _min){
    result = _min;
  }else if (_v1 > _max){
    result = _max;
  }else{
    result = _v1;
  }return result;
}

double smoothlist_0[1];
int smoothindex_0 = 0;
double smoothtotal_0 = 0.0;

//Smoothing Function: Smooth (or average) an incoming value based on (N) number of samples.
double Smoothing_Moving_Average(double _v1, int _n, double *_list, int *_index, double *_total){
  *_total -= _list[*_index];
  *_total += _v1;
  _list[*_index] = _v1;
  (*_index)++;
  if (*_index >= _n) *_index = 0;
  return *_total/(double)_n;
}

//******************** End Function Definitions ********************

Servo servo1;

void setup() {
  int smi;
  for(smi = 0; smi < 1; ++smi) {
    smoothlist_0[smi] = 0.0;
  }
  servo1.attach(1);
}

void loop() {
  digitalWrite(1, Multiplication(Remap_Numbers(Analog_Pin_0,Interval(100,250),Interval(1,0)),0));
  digitalWrite(1, Multiplication(Remap_Numbers(Analog_Pin_0,Interval(100,250),Interval(0,1)),0));
  servo1.write(Smoothing_Moving_Average(Remap_Numbers(Constrain(Analog_Pin_0,Interval(100,250)),Interval(100,250),Interval(85,99)),1, smoothlist_0, &smoothindex_0, &smoothtotal_0));
}

Errors-


Arduino: 1.8.15 (Windows Store 1.8.49.0) (Windows 10), Board: "Arduino Uno"

D:\SCET\Academics\5th Year\Research\Firefly\Firefly.ino: In function 'void loop()':

Firefly:70:48: error: 'Analog_Pin_0' was not declared in this scope

   digitalWrite(1, Multiplication(Remap_Numbers(Analog_Pin_0,Interval(100,250),Interval(1,0)),0));

                                                ^~~~~~~~~~~~

D:\SCET\Academics\5th Year\Research\Firefly\Firefly.ino:70:48: note: suggested alternative: 'analogWrite'

   digitalWrite(1, Multiplication(Remap_Numbers(Analog_Pin_0,Interval(100,250),Interval(1,0)),0));

                                                ^~~~~~~~~~~~

                                                analogWrite

Multiple libraries were found for "Servo.h"

 Used: C:\Users\Dell\Documents\Arduino\libraries\Servo

 Not used: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\libraries\Servo

exit status 1

'Analog_Pin_0' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

before I will show more hints there is something to do for you with your posted forum-posts
please re-edit your post #1 and post #6 by using the pencil-icon at the end of the post.

mark the complete error-message then
press Ctrl-X for cut-out the errormessage
press the <|>-Button above the edit-field to let insert

type or paste code here

and then press Ctrl-V to re-insert the error-messages.
then click on save edit below the edit-field

This will re-write the error-message as a code-section
best regards Stefan

As you are using firefly
I recommend to ask here

They promise

Firefly alleviates the hassle of interfacing with external hardware.

Well so it should take just a small post and a small hint from the firefly-experts to make it work!
best regards Stefan