Hi there,
I have an ultrasonic sensor and 7 chainable leds connected to my grove board.
I want to measure people walking past the ultrasonic sensor and then give a light signal through the leds, one after the other.
I succeeded making this work.
My question is how can I make it work that if the leds are still on from 1 person passing by, but another person passing by that the leds also start showing the leds lighting up for that person.
So two signals through the leds at the same time.
I now tried to do that with a loop inside the void loop, but now the ultrasonic sensor stops measuring when the leds are lightning up.
Hope you can help! Thanks in advance!
#include <SoftwareSerial.h>
#include <Wire.h>
#include <rgb_lcd.h>
#include <Ultrasonic.h>
//#include "Ultrasonic.h"
#include <ChainableLED.h>
#define LED_PIN 3
#define NUM_LEDS 7
ChainableLED leds(2, 3, NUM_LEDS);//defines the pin used on arduino.
Ultrasonic ultrasonic(4);
int distance;
int maximumRange = 150; // Maximum range needed
int minimumRange = 10; // Minimum range needed
int color = 0;
long RangeInCentimeters;
float hue = 1.0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
// Dit is de nieuwe functie die je boven je 'void loop()' zet.
void lightItUp() {
// Zet hier je code in die je LEDs aan zet.
for(byte i=0;i<NUM_LEDS;i++){
leds.setColorRGB(i, 0, 0, 255);
delay(600);
}
// Zet hier je code in die je LEDs uit zet.
// delay(200);
for(byte i=0;i<NUM_LEDS;i++){
leds.setColorRGB(i, 0, 0, 0);
delay(10);
}
}
// Dit is de normale 'void loop()' functie die altijd in je code staat.
void loop() {
RangeInCentimeters = ultrasonic.MeasureInCentimeters(); // two measurements should keep an interval
Serial.print(RangeInCentimeters);
Serial.println(" cm");
if (RangeInCentimeters >= maximumRange || RangeInCentimeters <= minimumRange) {
leds.setColorRGB(1, 0, 0, 0);
}
else {
//Dit is de functie die je aanroept. Dit is 'void lightItUp()'.
lightItUp();
}
}