Home / How To / Infinity Mirror With LCD and IR Sensor: 5 steps

Infinity Mirror With LCD and IR Sensor: 5 steps



For this project I use some libraries that you would need to download to use. I'll put them here, remember that I'm on Windows so it can be effective if you're on a Mac or Linux.

You must change the number of pixels depending on the number of LEDs you have. I have also built in a Serial Monitor interface so that you can connect with it if you do not use an IR sensor.

  // Library

#include Adafruit_NeoPixel.h>
#include 
#include 
#include  // Pins and Constant values


// Pins and Constant values ​​
const int RECV_PIN = 12; IRrecv irrecv (RECV_PIN); decode results; unsigned long key_value = 0; const int NUMPIXELS = 27;

Adafruit_NeoPixel pixels = Adafruit_NeoPixel (NUMPIXELS, 3); LiquidCrystal_I2C LCD (0x27, 2, 1

, 0, 4, 5, 6, 7, 3, POSITIVE); // Variables int IRNumb; int IRNumb2; int rainbow = 0; uint32_t rainbowColor = pixels.Color (0, 0, 0); char input = 0; char input2 = 0; int r; int g; int b; int breakCondition = 0; void setup () { // Initializes elements that do not need to be repeated. LCD (16.2); // Defines 16 columns and 2 rows LCD display lcd.backlight (); // To turn on the backlight Serial.start (9600); pixels.start (); irrecv.enableIRIn (); Serial.println ("Enter a 0 to turn off the lights"); // Start Instructions Serial.println ("Enter a 1 to turn the LED lights to white"); Serial.println ("Enter a 2 for the LED lights to go through different colors"); Serial.println ("Enter a 3 to customize the LED colors manually"); } void loop () { IRNumb = 10; IRScan (); mainOptions (); if (Serial.available ()> 0) {// Check if a character is available? input = (char) Serial.read (); } // Select the different options if (input == & # 39; 1 & # 39; || IRNumb == 1) { rainbowColor = colorChange (255,255,255); // White SetAll (rainbowColor); // Updating LED lights } otherwise if (input ==> 0 & # 39; || IRNumb == 0) { rainbowColor = colorChange (0,0,0); // Off SetAll (rainbowColor); // Updating LED lights } otherwise if (input == & 2; 2 & # 39; || IRNumb == 2) { breakCondition = 0; r = 0; g = 0; b = 0;

Serial.println ("Enter something that is not a 2 to end this effect, then one of the preventive options for a new effect."); lcd.clear (); // Clean the screen lcd.setCursor (0,0); lcd.print ("Exit using any-"); LCD set cursor (0.1); lcd.print ("numb it! = 2"); for (inti = 0; in < 255; i++ ) { // First effect strts input = (char)Serial.read(); IRScan(); if ((input != '2' && input != ' ' && input > = 48 && input <= 57) || breakCondition == 1 || IRNumb! = 2) {// Checks whether the effect must be terminated rainbowColor = colorChange (0,0,0); SetAll (rainbowColor); breakCondition = 1; break; } rainbowColor = colorChange (i, 0, 0); SetAll (rainbowColor); showStrip (); delay (100); } for (inti = 0; in < 255; i++ ) { // Second effect input = (char)Serial.read(); IRScan(); if ((input != '2' && input != ' ' && input > = 48 && input <= 57) || breakCondition == 1 || IRNumb! = 2) {// Checks whether the effect must be terminated rainbowColor = colorChange (0,0,0); SetAll (rainbowColor); breakCondition = 1; break; } g ++; rainbowColor = colorChange (i, g, 0); SetAll (rainbowColor); showStrip (); delay (100); } for (int g = 0; g < 255; g++ ) { // Third effect input = (char)Serial.read(); IRScan(); if ((input != '2' && input != ' ' && input > = 48 && input <= 57) || breakCondition == 1 || IRNumb! = 2) {// Checks whether the effect must be terminated rainbowColor = colorChange (0,0,0); SetAll (rainbowColor); breakCondition = 1; break; } r + = 2; rainbowColor = colorChange (r, g, 0); SetAll (rainbowColor); showStrip (); delay (100); } for (int b = 0; b < 255; b++ ) { // Fourth effect input = (char)Serial.read(); IRScan(); if ((input != '2' && input != ' ' && input > = 48 && input <= 57) || breakCondition == 1 || IRNumb! = 2) {// Checks whether the effect must be terminated rainbowColor = colorChange (0,0,0); SetAll (rainbowColor); breakCondition = 1; break; } r + = 2; g + = 5; rainbowColor = colorChange (r, g, b); SetAll (rainbowColor); showStrip (); delay (100); } mainOptions (); } otherwise if (input ==> 3 & # 39; || IRNumb == 3) { r = 0; g = 0; b = 0;

Serial.println ("Enter n to exit"); Serial.println ("Use w and s to increase or decrease the red color"); Serial.println ("Use r and f to increase or decrease the green color"); Serial.println ("Use y and h to increase or decrease the blue color"); lcd.clear (); // Clean the screen lcd.setCursor (0,0); lcd.print ("exit: 0.4 / 7: +/- red"); LCD set cursor (0.1); lcd.print ("5/8: green, 6/9: blue");

while (input2! = & # 39; n & # 39; IRNumb2 ||! = 0) { if (Serial.available ()> 0) {// is a character available? input2 = (char) Serial.read (); } //Serial.println(IRNumb2); IRNumb2 = 10; IRScan2 ();

on (IRNumb2 == 0) { break; } if (input2 == & # 39; w & # 39; || IRNumb2 == 4) { r + = 2; rainbowColor = colorChange (r, g, b); SetAll (rainbowColor); showStrip (); } else if (input2 == & # 39; s & # 39; || IRNumb2 == 7) { r- = 2; rainbowColor = colorChange (r, g, b); SetAll (rainbowColor); showStrip (); } else if (input2 == & # 39; r & # 39; || IRNumb2 == 5) { g + = 2; rainbowColor = colorChange (r, g, b); SetAll (rainbowColor); showStrip (); } else if (input2 == & # 39; f & # 39; || IRNumb2 == 8) { g- = 2; rainbowColor = colorChange (r, g, b); SetAll (rainbowColor); showStrip (); }

Otherwise (input2 == & # 39; y & # 39; || IRNumb2 == 6) { b + = 2; rainbowColor = colorChange (r, g, b); SetAll (rainbowColor); showStrip (); }

Otherwise (input2 == & # 39; h | # IRNumb2 == 9) { b- = 2; rainbowColor = colorChange (r, g, b); SetAll (rainbowColor); showStrip (); } } mainOptions (); } SetAll (rainbowColor); showStrip (); } void showStrip () { pixels.show (); } void setAll (uint32_t color) { for (int i = 0; i <NUMPIXELS; in ++) { pixels.setPixelColor (i, color); } } // Enter a value of 0 to 255 to get a color value. uint32_t colorChange (int r, int g, int b) { return pixels. Colors (r, g, b); } void mainOptions () {// Lakes the main power options lcd.clear (); // Clean the screen lcd.setCursor (0,0); lcd.print ("0 for Lights Off"); LCD set cursor (0.1); lcd.print ("1: White Light"); delay (1000); lcd.clear (); // Clean the screen lcd.setCursor (0,0); lcd.print ("2: Color effect"); LCD set cursor (0.1); lcd.print ("3: Manual"); delay (1000); } void IRScan () { to convert (irrecv.decode (& results)) {

(results.value == 0XFFFFFFFF) results.value = key_value; Other{ //Serial.println(results.value, HEX); if (results.value == == 0xFF6897 || results.value 0xC101E57B) { IRNumb = 0; //Serial.println("0 "); } else if (results.value == == 0x9716BE3F || results.value 0xFF30CF) { IRNumb = 1; //Serial.println("1 "); } otherwise if (results.value == 0x3D9AE3F7 || results.value == 0xFF18E7) ​​{ IRNumb = 2; //Serial.println("2 "); } else if (results.value == == 0xFF7A85 || results.value 0x6182021B) { IRNumb = 3; // Serial.println ("3"); } else if (results.value == == 0x8C22657B || results.value 0xFF10EF) { IRNumb = 4; //Serial.println("4 "); } otherwise if (results.value == 0xFF38C7 ​​|| results.value == 0x488F3CBB) { IRNumb = 5; // Serial.println ("5"); } otherwise if (results.value == 0x449E79F || results.value == 0xFF5AA5) { IRNumb = 6; // Serial.println ("6"); } otherwise if (results.value == 0xFF42BD || results.value == 0x32C6FDF7) { IRNumb = 7; //Serial.println("7 "); } otherwise if (results.value == 0x1BC0157B || results.value == 0xFF4AB5) { IRNumb = 8; //Serial.println("8 "); } else if (results.value == == 0xFF52AD || results.value 0x3EC3FC1B) { IRNumb = 9; // Serial.println ("9"); } } key_value = results.value; irrecv.resume (); } } void IRScan2 () { to convert (irrecv.decode (& results)) {

(results.value == 0XFFFFFFFF) results.value = key_value; Other{ // Serial.println (results.value, HEX); if (results.value == == 0xFF6897 || results.value 0xC101E57B) { IRNumb2 = 0; //Serial.println("0 "); } else if (results.value == == 0x9716BE3F || results.value 0xFF30CF) { IRNumb2 = 1; //Serial.println("1 "); } otherwise if (results.value == 0x3D9AE3F7 || results.value == 0xFF18E7) ​​{ IRNumb2 = 2; //Serial.println("2 "); } else if (results.value == == 0xFF7A85 || results.value 0x6182021B) { IRNumb2 = 3; // Serial.println ("3"); } else if (results.value == == 0x8C22657B || results.value 0xFF10EF) { IRNumb2 = 4; //Serial.println("4 "); } otherwise if (results.value == 0xFF38C7 ​​|| results.value == 0x488F3CBB) { IRNumb2 = 5; // Serial.println ("5"); } else if (results.value == == 0x449E79F || results.value 0xFF5AA5) { IRNumb2 = 6; // Serial.println ("6"); } otherwise if (results.value == 0xFF42BD || results.value == 0x32C6FDF7) { IRNumb2 = 7; //Serial.println("7 "); } otherwise if (results.value == 0x1BC0157B || results.value == 0xFF4AB5) { IRNumb2 = 8; //Serial.println("8 "); } otherwise if (results.value == 0xFF52AD || results.value == 0x3EC3FC1B) { IRNumb2 = 9; // Serial.println ("9"); } } key_value = results.value; irrecv.resume (); } }


Source link