Upload to Arduino Failed, when I use both "timer" and "read ultrasonic sensor"


#1

Hi,

My project use the “timer” and “read ultrasonic sensor …”.
When I want to upload to Arduino, I got the Error.

NG_Extensions.sb2 (73.0 KB)


#2

@tec_support, there is an error in the code generator. It failed to declare vt and also failed to put in the closing brace on the getLastTime() method (see corrected code below:

#include <Arduino.h>
#include <Wire.h>
#include <SoftwareSerial.h>

double angle_rad = PI/180.0;
double angle_deg = 180.0/PI;
double vu;
double vt;  // <--- added declaration for vt

float getDistance(int trig,int echo){
    pinMode(trig,OUTPUT);
    digitalWrite(trig,LOW);
    delayMicroseconds(2);
    digitalWrite(trig,HIGH);
    delayMicroseconds(10);
    digitalWrite(trig,LOW);
    pinMode(echo, INPUT);
    return pulseIn(echo,HIGH,30000)/58.0;
}

double currentTime = 0;
double lastTime = 0;
double getLastTime(){
	return currentTime = millis()/1000.0 - lastTime;
} // <---- added closing brace

void setup(){
    vu = getDistance(13,12);
    vt += getLastTime();        
}

void loop(){
    _loop();
}

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

void _loop(){
}

#3

Hi wpopoily & Charles,

We have verified this issue and added it to the repair list.
Thanks for your feedback!


#4

Hi chuckmcknight,

Yes, I can do it by Arduino IDE.
But children can’t correct it by themselves, they don’t know the Arduino IDE.


#5

Hi tec_support,

That is great!

And about the other feekback - "When use “Timer”feature, the mBlock 3.4.5 something wrong"
Whether the mblock team also verified it !?

When use "Timer"feature, the mBlock 3.4.5 something wrong


#6

Hi @wpopoily,

Yup, that’s why I copied in @tec_support because it is an issue in the code generator. It is fixable in the Arduino IDE, but the bug really needed to be reported. :slight_smile:

Regards,

Chuck


#7

Hi wpopoily,

Thanks! I have provide feedback about this one to our engineers either.
Will let you know when get the reply.


#8

Hi mBlock team,

The v3.4.8 still lose the closing brace.
The problem has been a long time.
Could you solve this problem?
Thank you very much.


#9

Hi wpopoily,

Actually, our engineers have fixed this issue, but it still cause losing the closing brace on the other program block.
Hopefully we can fix it on the next version,thanks for your feedback!


#10

Actually, I have many the customized blocks(function) to do something in my project.
So I very much hope that the problem can be solved earlier.

Now, I try v4.0.1 seems to fix it.
But the v4.0.1 has a problem, there is no “Save” prompt,
before the program leaves or loads other projects.


#11

Yes, there is no “Save” prompt on v4.0.1, while there is plan to add the undo function in the future.