#include <FastLED.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <IRremoteESP8266.h>
#include <IRrecv.h>
#include <IRutils.h>

double R;
double A;
double V;
double Codigomandonum;
double I;
double J;
String s_CODIGOMANDO;
CRGB neopixelFL_leds[64];
Adafruit_SSD1306 oled_1(128,64, &Wire,-1);
bool oled_1_autoshow=true;
IRrecv ir_rx(2);
decode_results ir_rx_results;
unsigned long ir_rx_results_value=0;
String ir_rx_results_protocol="";
int ir_rx_results_bits=0;

String fnc_ir_rx_decode_txt()
{
	char buff[16];
	buff[0]=0;
	ir_rx_results_value=0;
	ir_rx_results_bits=0;
	ir_rx_results_protocol="";
	if(ir_rx.decode(&ir_rx_results))
	{
		sprintf(buff,"%08lX",(unsigned long)ir_rx_results.value);
		ir_rx_results_value=(unsigned long)ir_rx_results.value;
		ir_rx_results_bits=ir_rx_results.bits;
		if(ir_rx_results.decode_type==RC5)ir_rx_results_protocol="RC5";
		else if(ir_rx_results.decode_type==RC6)ir_rx_results_protocol="RC6";
		else if(ir_rx_results.decode_type==NEC)ir_rx_results_protocol="NEC";
		else if(ir_rx_results.decode_type==SONY)ir_rx_results_protocol="SONY";
		else if(ir_rx_results.decode_type==PANASONIC)ir_rx_results_protocol="PANASONIC";
		else if(ir_rx_results.decode_type==JVC)ir_rx_results_protocol="JVC";
		else if(ir_rx_results.decode_type==SAMSUNG)ir_rx_results_protocol="SAMSUNG";
		else if(ir_rx_results.decode_type==WHYNTER)ir_rx_results_protocol="WHYNTER";
		else if(ir_rx_results.decode_type==AIWA_RC_T501)ir_rx_results_protocol="AIWA";
		else if(ir_rx_results.decode_type==LG)ir_rx_results_protocol="LG";
		else if(ir_rx_results.decode_type==SANYO)ir_rx_results_protocol="SANYO";
		else if(ir_rx_results.decode_type==MITSUBISHI)ir_rx_results_protocol="MITSUBISHI";
		else if(ir_rx_results.decode_type==DENON)ir_rx_results_protocol="DENON";
		ir_rx.resume();
	}
	return String(buff);
}

void ROJO() {
	R = 0;
	for (int count = 0; count < 64; count++) {
		neopixelFL_leds[(int)(R)].r = 204;
		neopixelFL_leds[(int)(R)].g = 0;
		neopixelFL_leds[(int)(R)].b = 0;
		R=R+(1);
		FastLED.show();
	}
}
void AMARILLO() {
	A = 0;
	for (int count = 0; count < 64; count++) {
		neopixelFL_leds[(int)(A)].r = 255;
		neopixelFL_leds[(int)(A)].g = 255;
		neopixelFL_leds[(int)(A)].b = 0;
		A=A+(1);
		FastLED.show();
	}
}
void VERDE() {
	V = 0;
	for (int count = 0; count < 64; count++) {
		neopixelFL_leds[(int)(V)].r = 0;
		neopixelFL_leds[(int)(V)].g = 153;
		neopixelFL_leds[(int)(V)].b = 0;
		V=V+(1);
		FastLED.show();
	}
}

void setup()
{
  	pinMode(25, OUTPUT);
	pinMode(32, OUTPUT);
	pinMode(33, OUTPUT);

	ir_rx.enableIRIn();

	FastLED.addLeds<WS2812B, 13,GRB>(neopixelFL_leds,64);
	oled_1.begin(SSD1306_SWITCHCAPVCC,0x3C);
	oled_1.clearDisplay();
	if(oled_1_autoshow)oled_1.display();
	oled_1.setTextSize(1);
	oled_1.setTextColor(WHITE);
	oled_1.setCursor(0,0);
	oled_1.print(String("Semáforo Peatonal"));
	if(oled_1_autoshow)oled_1.display();
	oled_1.setTextSize(1);
	oled_1.setTextColor(WHITE);
	oled_1.setCursor(0,30);
	oled_1.print(String("con alarma"));
	if(oled_1_autoshow)oled_1.display();
	oled_1.display();
	I = 3;
	J = I;
	digitalWrite(25, LOW);
	digitalWrite(32, LOW);
	digitalWrite(33, LOW);

}


void loop()
{
	yield();

  	oled_1.clearDisplay();
  	if(oled_1_autoshow)oled_1.display();
  	s_CODIGOMANDO = fnc_ir_rx_decode_txt();
  	Codigomandonum = (unsigned long)((String(s_CODIGOMANDO).toFloat()));
  	oled_1.setTextSize(1);
  	oled_1.setTextColor(WHITE);
  	oled_1.setCursor(0,0);
  	oled_1.print(String("CODIGO"));
  	if(oled_1_autoshow)oled_1.display();
  	oled_1.setTextSize(3);
  	oled_1.setTextColor(WHITE);
  	oled_1.setCursor(0,30);
  	oled_1.print(Codigomandonum);
  	if(oled_1_autoshow)oled_1.display();
  	if ((Codigomandonum == 20)) {
  		digitalWrite(32, HIGH);
  	}

  	if ((Codigomandonum == 0)) {
  		digitalWrite(32, LOW);
  	}

  	delay(3000);

}
$abcdeabcde151015202530fghijfghij