Hello everyone ,
I have a small problem with my program, I can't display what I want on my console.
If you could help me that would be nice.
just below, thanks again !
const byte TRIGGER_PIN = 6; // Broche TRIGGER``
const byte ECHO_PIN = 5; // Broche ECHO
const unsigned long MEASURE_TIMEOUT = 25000UL; // 25ms = ~8m à 340m/s
const float SOUND_SPEED = 340.0 / 1000;
float distance;
void setup()
{
Serial.begin(9600);
pinMode(TRIGGER_PIN, OUTPUT);
digitalWrite(TRIGGER_PIN, LOW); // La broche TRIGGER doit être à LOW au repos
pinMode(ECHO_PIN, INPUT);
}
void loop()
{
if(distance >= 10)
{
Serial.println("pas de spray");
delay(500);
}
else
{
Serial.println("spray enclenché");
delay(500);
}
Read the forum guidelines to see how to properly post code and some good information on making a good post.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.
Please go back and fix your original post
If there are errors, please include the entire error message. It is easy to do. There is a button (lower right of the IDE window) called "copy error message". Copy the error and paste into a post in code tags. Paraphrasing the error message leaves out important information.
Indeed, a description of the problem would be helpful and the code would be easier to read if placed within code tags. Incidentally, OP, you do not appear to be setting the variable 'distance' nor calling measure_dist() within the main loop so not much is going to happen here...
You should have mentioned in your original post that you have errors and posted the errors.
float distance_mm = measure / 2.0 * SOUND_SPEED;
'measure' was not declared in this scope
The line that creates the variable measure is inside of a comment so that variable does not exist. Comments are either 2 slashes (//) or the block comment (/*, */). Single slashes are just errors. Be more careful with your commenting.
/ Serial.print(F("Distance: ")); /
error: expected primary-expression before '/' token
Single slashes don't mean anything and will just cause errors.
distance = (distance_mm / 10.0, 2);
warning: left operand of comma operator has no effect
Only a warning, but should be fixed. The comma has no place in that statement. What are you trying to do there?