Error message when upload in arduino uno


#1

Hi !
I want to create some extension for control an arduino robot for my students(middle school), but when I’m uploading on arduino uno the blocks program I have the compile error :

"In function ‘void setup()’: C:\Users\Vincent\mblock-avr\temp\build\code.cpp:28:3: error: a function-definition is not allowed here before ‘{’ token { ^

Failed to compile file code.cpp

arduino build failed."

the ArduinoC code is
#include <Arduino.h>
#include <Wire.h>
#include <SoftwareSerial.h>

void _delay(float seconds) {
long endTime = millis() + seconds * 1000;
while(millis() < endTime) _loop();
}

void setup() {
void goduringandcorrection(double pcent, double fac, double nsec)
{
analogWrite(5,(pcent255)/100); //convert PWM value to %
digitalWrite(6,0); //left motor go ahead
digitalWrite(7,1); //
analogWrite(10,((pcent
255)/fac)/100); // corecting one motor if imbalance
digitalWrite(8,0); //right motor go ahead
digitalWrite(9,1); //
_delay(nsec);
analogWrite(5,0); // stop left
analogWrite(10,0); // stop right
}

}

void _loop() {
}

void loop() {
_loop();
}

Thanks a lot for your answers !!!


#2

you have put a function inside you setup loop or inside the code part in the extension builder
"void setup() {
void goduringandcorrection(double pcent, double fac, double nsec)
{
analogWrite(5,(pcent255)/100); //convert PWM value to %
digitalWrite(6,0); //left motor go ahead
digitalWrite(7,1); //
analogWrite(10,((pcent255)/fac)/100); // corecting one motor if imbalance
digitalWrite(8,0); //right motor go ahead
digitalWrite(9,1); //
_delay(nsec);
analogWrite(5,0); // stop left
analogWrite(10,0); // stop right
}

}"

Fuctions need to go in the declare part of the extension builder


#3

Thanks a lot ! Just a last question : in mblock5, when I drag my command block(s) under “when Arduino uno starts”, the functions do not appear in setup().

what should i configure in mblock builder so that the functions are called by setup() ?

Thanks in advance.


#4

I managed to include my functions in the setup() by writing them in the “code” under mblock builder, but I don’t know how to synchronize the values of the variables of the functions with those written in the corresponding blocks.
When I write something in the code under mblock builder, it’s wrote the same thing under mblock5, and I can’t changed the values of variables in the blocks. In resume it’s fixed !

Thank you very much for your help in advance !!


#5

Functions do not go inside setup. The code that calls them does. Functions need to be put in the declare part of the extension builder


#6

I’ve well understood for the declaration of the functions, but when I’m calling a function in the code, what, for example, I need to write under mblock builder blocks settings ?


#7

in the code section is what will be placed in your program when the block is placed.

open the code tab so you see see what code is be generated by the block you created


#8

Good morning,
I know this tab and I open it frequently. But, under mblock extension bluider , when I write in the code for example : goduringandcorrection(50, 2, 1.25); , hence I download the .dev file to drag it on mblock5, and I drag the blocks “when arduino starts” and the block corresponding to this function, in the tab you were talking before, in the code, we can see “goduringandcorrection(50, 2, 1.25)” even if I change the numbers in the block. It’s fixed and I can’t change the parameters in the block.
I think I need to “synchronize” or “associated” the parameters of the block to the variables of the function, but I don’t know how !
Thanks for your help.


#9

I make you quick video to explain see https://www.youtube.com/watch?v=SEDei4Hf67I&feature=youtu.be


#10

It works !! Thank you very much !


#11

Hi !
I 've got a simple problem, but not so simple actually !
I’ve include <IRremote.h> in the “include” on mblock Extension Builder, and when compile this, I’ve the error message :

C:\Users\Vincent\mblock-avr\temp\build\code.cpp:1:10: fatal error: IRremote.h: No such file or directory #include <IRremote.h> ^~~~~~~~~~~~ compilation terminated.

Failed to compile file code.cpp

arduino build failed.

It’s very strange because I know that I’ve uploaded the IRremote.h librarie in “Add source file” in a folder as usual, IRemote.h is correctly spelled, and I made the same things for Servo.h librarie but it works for this !

Thanks in advance for your anwser.