#include <Adafruit_NeoPixel.h>
#include <Ultrasonic.h>
#define PIN 6
//#define NUMPIXELS 64
#define PIXEL_AMOUNT 64
#define BRIGHTNESS 150
int distance1 = 0;
int distance2 = 0;
int distance3 = 0;
int distance4 = 0;
int dist1 = 0;
int dist2 = 0;
int dist3 = 0;
int dist4 = 0;
int d1 = 0;
int d2 = 0;
int d3 = 0;
int d4 = 0;
int row_excel = 5;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(64, 6, NEO_GRB + NEO_KHZ800);
Ultrasonic ultrasonic1(1, 0); // An ultrasonic sensor HC-04
Ultrasonic ultrasonic2(5, 4); // An ultrasonic sensor HC-04
Ultrasonic ultrasonic3(10, 11); // An ultrasonic sensor HC-04
Ultrasonic ultrasonic4(8, 7); // An ultrasonic sensor HC-04
int showType = 3;
void setColor(uint32_t c) {
for(uint16_t i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, c);
}
strip.show();
}
void setup() {
Serial.begin(9600);
strip.begin();
strip.show();
Serial.println("CLEARDATA");
Serial.println("Time, Sensor 01, Sensor 02, Sensor 03, Sensor 04");
}
void loop() {
{
row_excel++;
Serial.print("DATA,TIME,");
Serial.print(",");
if (ultrasonic1.read(CM)< 30)
//Serial.print("Sensor 01: ");
Serial.print(ultrasonic1.read(CM)); // Prints the distance on the default unit (centimeters)
//Serial.println("cm");
Serial.print(",");
if (ultrasonic2.read(CM)<30)
//Serial.print("Sensor 02: ");
Serial.print(ultrasonic2.read(CM)); // Prints the distance on the default unit (centimeters)
//Serial.println("cm");
Serial.print(",");
if (ultrasonic3.read(CM)<30)
//Serial.print("Sensor 03: ");
Serial.print(ultrasonic3.read(CM)); // Prints the distance in inches
//Serial.println("cm");
Serial.print(",");
if (ultrasonic4.read(CM)<30)
//Serial.print("Sensor 04: ");
Serial.print(ultrasonic4.read(CM)); // Prints the distance in inches
//Serial.println("cm");
Serial.print(",");
Serial.println(row_excel);
delay(100);
distance1 = ultrasonic1.read();
distance2 = ultrasonic2.read();
distance3 = ultrasonic3.read();
distance4 = ultrasonic4.read();
dist1 = ultrasonic1.read();
dist2 = ultrasonic2.read();
dist3 = ultrasonic3.read();
dist4 = ultrasonic4.read();
d1 = ultrasonic1.read();
d2 = ultrasonic2.read();
d3 = ultrasonic3.read();
d4 = ultrasonic4.read();
}
// 1 line
if ( distance1 >= 4 && distance1 <= 6 )
strip.setPixelColor(0, strip.Color(127, 127, 127));
else if ( distance1 >= 7 && distance1 <= 9 )
strip.setPixelColor(1, strip.Color(127, 127, 127));
else if ( distance1 >= 10 && distance1 <= 12 )
strip.setPixelColor(2, strip.Color(127, 127, 127));
else if ( distance1 >= 13 && distance1 <= 15 )
strip.setPixelColor(3, strip.Color(127, 127, 127));
else if ( distance1 >= 16 && distance1 <= 18 )
strip.setPixelColor(4, strip.Color(127, 127, 127));
else if ( distance1 >= 19 && distance1 <= 21 )
strip.setPixelColor(5, strip.Color(127, 127, 127));
else if ( distance1 >= 22 && distance1 <= 24 )
strip.setPixelColor(6, strip.Color(127, 127, 127));
else if ( distance1 >= 25 && distance1 <= 27 )
strip.setPixelColor(7, strip.Color(127, 127, 127));
// 2 line
else if ( d1 >= 4 && d1 <= 6 == d2 >= 4 && d2 <= 6 )
strip.setPixelColor(8, strip.Color(127, 127, 127));
else if ( d1 >= 7 && d1 <= 9 == d2 >= 7 && d2 <= 9 )
strip.setPixelColor(9, strip.Color(127, 127, 127));
else if (d1 >= 10 && d1 <= 12 == d2 >= 10 && d2 <= 12 )
strip.setPixelColor(10, strip.Color(127, 127, 127));
else if (d1 >= 13 && d1 <= 15 == d2 >= 13 && d2 <= 15 )
strip.setPixelColor(11, strip.Color(127, 127, 127));
else if (d1 >= 16 && d1 <= 18 == d2 >= 16 && d2 <= 18 )
strip.setPixelColor(12, strip.Color(127, 127, 127));
else if (d1 >= 19 && d1 <= 21 == d2 >= 19 && d2 <= 21 )
strip.setPixelColor(13, strip.Color(127, 127, 127));
else if (d1 >= 22 && d1 <= 24 == d2 >= 22 && d2 <= 24 )
strip.setPixelColor(14, strip.Color(127, 127, 127));
else if (d1 >= 24 && d1 <= 27 == d2 >= 25 && d2 <= 27 )
strip.setPixelColor(15, strip.Color(127, 127, 127));
//3 line
else if ( distance2 >= 4 && distance2 <= 6 )
strip.setPixelColor(16, strip.Color(127, 127, 127));
else if ( distance2 >= 7 && distance2 <= 9 )
strip.setPixelColor(17, strip.Color(127, 127, 127));
else if ( distance2 >= 10 && distance2 <= 12 )
strip.setPixelColor(18, strip.Color(127, 127, 127));
else if ( distance2 >= 13 && distance2 <= 15 )
strip.setPixelColor(19, strip.Color(127, 127, 127));
else if ( distance2 >= 16 && distance2 <= 18 )
strip.setPixelColor(20, strip.Color(127, 127, 127));
else if ( distance2 >= 19 && distance2 <= 21 )
strip.setPixelColor(21, strip.Color(127, 127, 127));
else if ( distance2 >= 22 && distance2 <= 24 )
strip.setPixelColor(22, strip.Color(127, 127, 127));
else if ( distance2 >= 25 && distance2 <= 27 )
strip.setPixelColor(23, strip.Color(127, 127, 127));
//4 line
else if ( dist2 >= 4 && dist2 <= 6 | dist3 >= 4 && dist3 <= 6 )
strip.setPixelColor(24, strip.Color(127, 127, 127));
else if ( dist2 >= 7 && dist2 <= 9 | dist3 >= 7 && dist3 <= 9 )
strip.setPixelColor(25, strip.Color(127, 127, 127));
else if (dist2 >= 10 && dist2 <= 12 | dist3 >= 10 && dist3 <= 12 )
strip.setPixelColor(26,strip.Color(127, 127, 127));
else if (dist2 >= 13 && dist2 <= 15 | dist3 >= 13 && dist3 <= 15 )
strip.setPixelColor(27, strip.Color(127, 127, 127));
else if (dist2 >= 16 && dist2 <= 18 | dist3 >= 16 && dist3 <= 18 )
strip.setPixelColor(28, strip.Color(127, 127, 127));
else if (dist2 >= 19 && dist2 <= 21 | dist3 >= 19 && dist3 <= 21 )
strip.setPixelColor(29, strip.Color(127, 127, 127));
else if (dist2 >= 22 && dist2 <= 24 | dist3 >= 22 && dist3 <= 24 )
strip.setPixelColor(30, strip.Color(127, 127, 127));
else if (dist2 >= 24 && dist2 <= 27 | dist3 >= 25 && dist3 <= 27 )
strip.setPixelColor(31, strip.Color(127, 127, 127));
//5 line
else if ( distance3 >= 4 && distance3 <= 6 )
strip.setPixelColor(32, strip.Color(127, 127, 127));
else if ( distance3 >= 7 && distance3 <= 9 )
strip.setPixelColor(33, strip.Color(127, 127, 127));
else if ( distance3 >= 10 && distance3 <= 12 )
strip.setPixelColor(34,strip.Color(127, 127, 127));
else if ( distance3 >= 13 && distance3 <= 15 )
strip.setPixelColor(35, strip.Color(127, 127, 127));
else if ( distance3 >= 16 && distance3 <= 18 )
strip.setPixelColor(36, strip.Color(127, 127, 127));
else if ( distance3 >= 19 && distance3 <= 21 )
strip.setPixelColor(37, strip.Color(127, 127, 127));
else if ( distance3 >= 22 && distance3 <= 24 )
strip.setPixelColor(38, strip.Color(127, 127, 127));
else if ( distance3 >= 25 && distance3 <= 27 )
strip.setPixelColor(39, strip.Color(127, 127, 127));
// 6 line
else if ( d3 >= 4 && d3 <= 6 == d4 >= 4 && d4 <= 6 )
strip.setPixelColor(40, strip.Color(127, 127, 127));
else if ( d3 >= 7 && d3 <= 9 == d4 >= 7 && d4 <= 9 )
strip.setPixelColor(41, strip.Color(127, 127, 127));
else if (d3 >= 10 && d3 <= 12 == d4 >= 10 && d4 <= 12 )
strip.setPixelColor(42, strip.Color(127, 127, 127));
else if (d3 >= 13 && d3 <= 15 == d4 >= 13 && d4 <= 15 )
strip.setPixelColor(43, strip.Color(127, 127, 127));
else if (d3 >= 16 && d3 <= 18 == d4 >= 16 && d4 <= 18 )
strip.setPixelColor(44, strip.Color(127, 127, 127));
else if (d3 >= 19 && d3 <= 21 == d4 >= 19 && d4 <= 21 )
strip.setPixelColor(45, strip.Color(127, 127, 127));
else if (d3 >= 22 && d3 <= 24 == d4 >= 22 && d4 <= 24 )
strip.setPixelColor(46, strip.Color(127, 127, 127));
else if (d3 >= 24 && d3 <= 27 == d4 >= 25 && d4 <= 27 )
strip.setPixelColor(47, strip.Color(127, 127, 127));
// 7 line
else if ( dist3 >= 4 && dist3 <= 6 | dist4 >= 4 && dist4 <= 6 )
strip.setPixelColor(48, strip.Color(127, 127, 127));
else if ( dist3 >= 7 && dist3 <= 9 | dist4 >= 7 && dist4 <= 9 )
strip.setPixelColor(49, strip.Color(127, 127, 127));
else if (dist3 >= 10 && dist3 <= 12 | dist4 >= 10 && dist4 <= 12 )
strip.setPixelColor(50, strip.Color(127, 127, 127));
else if (dist3 >= 13 && dist3 <= 15 | dist4 >= 13 && dist4 <= 15 )
strip.setPixelColor(51, strip.Color(127, 127, 127));
else if (dist3 >= 16 && dist3 <= 18 | dist4 >= 16 && dist4 <= 18 )
strip.setPixelColor(52, strip.Color(127, 127, 127));
else if (dist3 >= 19 && dist3 <= 21 | dist4 >= 19 && dist4 <= 21 )
strip.setPixelColor(53,strip.Color(127, 127, 127));
else if (dist3 >= 22 && dist3 <= 24 | dist4 >= 22 && dist4 <= 24 )
strip.setPixelColor(54, strip.Color(127, 127, 127));
else if (dist3 >= 24 && dist3 <= 27 | dist4 >= 25 && dist4 <= 27 )
strip.setPixelColor(55,strip.Color(127, 127, 127));
// 8 line
else if ( distance4 >= 4 && distance4 <= 6 )
strip.setPixelColor(56, strip.Color(127, 127, 127));
else if ( distance4 >= 7 && distance4 <= 9 )
strip.setPixelColor(57, strip.Color(127, 127, 127));
else if ( distance4 >= 10 && distance4 <= 12 )
strip.setPixelColor(58, strip.Color(127, 127, 127));
else if ( distance4 >= 13 && distance4 <= 15 )
strip.setPixelColor(59,strip.Color(127, 127, 127));
else if ( distance4 >= 16 && distance4 <= 18 )
strip.setPixelColor(60,strip.Color(127, 127, 127));
else if ( distance4 >= 19 && distance4 <= 21 )
strip.setPixelColor(61,strip.Color(127, 127, 127));
else if ( distance4 >= 22 && distance4 <= 24 )
strip.setPixelColor(62, strip.Color(127, 127, 127));
else if ( distance4 >= 25 && distance4 <= 27 )
strip.setPixelColor(63, strip.Color(127, 127, 127));
else strip.clear();
strip.show();
delay(100);
}
Comments