1
2
3
4
5#include <Ultrasonic.h>
6#include "FastLED.h"
7
8#define NUM_LEDS 512
9#define DATA_PIN 3
10CRGB leds[NUM_LEDS];
11
12const int someoneArrivedPin = 7;
13const int someoneLeftPin = 6;
14
15void setup() {
16 delay(2000);
17 FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS);
18 FastLED.setBrightness(150);
19 FastLED.clear();
20 Serial.begin(9600);
21 pinMode(someoneArrivedPin, OUTPUT);
22 pinMode(someoneLeftPin, INPUT);
23}
24
25Ultrasonic ultrasonic(someoneArrivedPin, someoneLeftPin);
26
27int randomInt;
28int randomInt2;
29
30void loop() {
31 for(int i = 0; i < 10; i++){
32 for(int j = 0; j < 1000; j++){
33 if (ultrasonic.read() > 10 and ultrasonic.read() <=100){
34 randomInt = (rand()%512);
35 randomInt2 = (rand()%256);
36 leds[randomInt].setHue(randomInt2);
37 FastLED.show();
38 }
39 }
40 for(int k = 512; k > 0; k--){
41 leds[k] = CRGB::Black;
42 FastLED.show();
43 }
44 }
45}