Вы находитесь на странице: 1из 4

include <Adafruit_NeoPixel.

h>
#define PIN 6
#define NUM_LEDS 60
#include "Wire.h" // F
#include "LCD.h"
#include "LiquidCrystal_I2C.h" // Added library*
#ifdef __AVR__
#include <avr/power.h>
#endif
char array1[]="ARE YOU BRAVE?
char array2[]="WELL DONE

";
";

const int trigPin = 2;


const int echoPin = 4;
long duration, inches, cm;
Adafruit_NeoPixel
NEO_KHZ800);

strip

Adafruit_NeoPixel(NUM_LEDS,

PIN,

NEO_GRB

LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7);
int tim = 50;
void setup()
{
lcd.begin (16,2); // 16 x 2 LCD module
lcd.setBacklightPin(3,POSITIVE); // BL, BL_POL
lcd.setBacklight(HIGH);
Serial.begin(9600);
// This is for Trinket 5V 16MHz, you can remove these three lines if you are not
using a Trinket
#if defined (__AVR_ATtiny85__)
if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
// End of trinket special code
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop()
{

pinMode(trigPin, OUTPUT);
digitalWrite(trigPin, LOW);
delayMicroseconds(20);
digitalWrite(trigPin, HIGH);
delayMicroseconds(100);
digitalWrite(trigPin, LOW);
// Read the signal from the sensor: a HIGH pulse whose
// duration is the time (in microseconds) from the sending
// of the ping to the reception of its echo off of an object.
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
// convert the time into a distance
cm = microsecondsToCentimeters(duration);
Serial.print(cm);
Serial.print("cm");
Serial.println();
//delay(50);
colorWipe(random(255), random(255), random(255), 0, cm);
colorWipe(random(255), random(255), random(255), 0, cm);
Strobe(0xff,0,0, 10, 20, 1000, cm);

lcd.home (); // Set cursor to 0,0


lcd.print("ARE YOU BRAVE?"); // Custom text
delay(tim);
lcd.clear();
}

long microsecondsToCentimeters(long microseconds)


{
// The speed of sound is 340 m/s or 29 microseconds per centimeter.
// The ping travels out and back, so to find the distance of the
// object we take half of the distance travelled.
return microseconds / 29 / 2;
}
void Strobe(byte red, byte green, byte blue, int StrobeCount, int FlashDelay, int
EndPause, int cm){
if(cm > 45){
for(int j = 0; j < StrobeCount; j++) {
setAll(red,green,blue);
showStrip();
delay(FlashDelay);
setAll(0,0,0);
showStrip();

delay(FlashDelay);
}
delay(EndPause);
}
}
void colorWipe(byte red, byte green, byte blue, int SpeedDelay, int cm) {
if(cm < 45)
{
for(uint16_t i=0; i<NUM_LEDS; i++) {
lcd.home (); // Set cursor to 0,0
lcd.print("WELL DONE!!!"); // Custom text
delay(tim);
lcd.clear();
setPixel(i, red, green, blue);
showStrip();
delay(SpeedDelay);
}
}
}
// *** REPLACE TO HERE ***
void showStrip() {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
strip.show();
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
FastLED.show();
#endif
}
void setPixel(int Pixel, byte red, byte green, byte blue) {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
strip.setPixelColor(Pixel, strip.Color(red, green, blue));
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
leds[Pixel].r = red;
leds[Pixel].g = green;
leds[Pixel].b = blue;
#endif
}
void setAll(byte red, byte green, byte blue) {
for(int i = 0; i < NUM_LEDS; i++ ) {
setPixel(i, red, green, blue);
}
showStrip();
}

Вам также может понравиться