Hello everyone,
I’m Tom and this is my first post on this forum. I’m currently working on a schoolproject with the Arduino Mega. I am making a device to help (almost) blind people, the device is controlled by an Arduino. Additionally I have 5 ultrasonic sensor connected to the arduino. At this moment the signal from the ultrasonic sensor is send to a LED to give the signal that an object is near. I know blind people won’t be able to see that, the LEDs are easier to use while programming, I wil change it later.
My code at this moment:
I had to put the code into a .TXT-file, because my post was to long. It is attached to the post.
The problem which I’m faced with has to do with programming. The code is almost ‘finished’, I only need to transfer the signal of the ultrasonic sensor to the LED. I want to do that through this code:
if (distance1 == 0) {
digitalWrite(ledPin1, HIGH);
delay(0);
digitalWrite(ledPin1, LOW);
delay(200);
}
if (distance1 > 0 && distance1 < 10) {
digitalWrite(ledPin1, HIGH);
delay(200);
digitalWrite(ledPin1, LOW);
delay(0);
}
if (distance1 >= 10 && distance1 < 20) {
digitalWrite(ledPin1, HIGH);
delay(175);
digitalWrite(ledPin1, LOW);
delay(25);
}
if (distance1 >= 20 && distance1 < 30) {
digitalWrite(ledPin1, HIGH);
delay(150);
digitalWrite(ledPin1, LOW);
delay(50);
}
if (distance1 >= 40 && distance1 < 50) {
digitalWrite(ledPin1, HIGH);
delay(125);
digitalWrite(ledPin1, LOW);
delay(75);
}
if (distance1 >= 50 && distance1 < 70) {
digitalWrite(ledPin1, HIGH);
delay(100);
digitalWrite(ledPin1, LOW);
delay(100);
}
if (distance1 >= 70 && distance1 < 100) {
digitalWrite(ledPin1, HIGH);
delay(75);
digitalWrite(ledPin1, LOW);
delay(125);
}
if (distance1 >= 100 && distance1 < 150) {
digitalWrite(ledPin1, HIGH);
delay(50);
digitalWrite(ledPin1, LOW);
delay(150);
}
if (distance1 >= 150 && distance1 < 200) {
digitalWrite(ledPin1, HIGH);
delay(25);
digitalWrite(ledPin1, LOW);
delay(175);
}
if (distance1 >= 200) {
digitalWrite(ledPin1, HIGH);
delay(0);
digitalWrite(ledPin1, LOW);
delay(200);
}
The only problem is the delays, I want all the 5 LEDs to blink their distance at the same time, not after eachother. As you are all aware, an Arduino can only process 1 thread at the time. I have done my research and tried to fix this with the library ‘TimedAction’. Ít didn’t work out for me, I can’t get it to work for me. All of the tutorials I watched aren’t sufficient enough for this more complex piece of coding.
If there is anyone who can give me a hint on what to do, or on what other libary I can use I would really appreciate it.
Thanks in advance,
Tom
PS_1: If you have questions, please ask!
PS_2: I’m a beginner in coding, please forgive me for my messy coding
PS_3: Where ‘//led pin code//’ stands, there will the ultrasonic to LED sequence come
PS_4 I’m very sorry for my English
Arduino code for blinds.txt (8.94 KB)