#include <FastLED.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <ESP32Servo.h>
#include <ABLocks_TimerFreeTone.h>

double R;
double A;
double V;
double I;
double J;
CRGB neopixelFL_leds[64];
Adafruit_SSD1306 oled_1(128,64, &Wire,-1);
bool oled_1_autoshow=true;
Servo servo_15;

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(4, INPUT);
	pinMode(25, OUTPUT);
	pinMode(32, OUTPUT);
	pinMode(33, OUTPUT);
	servo_15.attach(15);
	pinMode(26, OUTPUT);

	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;

}


void loop()
{
	yield();

  	while(!((!digitalRead(4))));
  	delay(2000);
  	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("TIENE 10 SEGUNDOS"));
  	if(oled_1_autoshow)oled_1.display();
  	oled_1.setTextSize(1);
  	oled_1.setTextColor(WHITE);
  	oled_1.setCursor(0,30);
  	oled_1.print(String("PARA PASAR"));
  	if(oled_1_autoshow)oled_1.display();
  	oled_1.display();
  	digitalWrite(25, LOW);
  	digitalWrite(32, HIGH);
  	digitalWrite(33, LOW);
  	servo_15.write(90);
  	delay(100);
  	VERDE();
  	delay(7000);
  	for (int count = 0; count < I; count++) {
  		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("LE QUEDAN"));
  		if(oled_1_autoshow)oled_1.display();
  		oled_1.setTextSize(1);
  		oled_1.setTextColor(WHITE);
  		oled_1.setCursor(0,30);
  		oled_1.print(J);
  		if(oled_1_autoshow)oled_1.display();
  		oled_1.setTextSize(1);
  		oled_1.setTextColor(WHITE);
  		oled_1.setCursor(0,50);
  		oled_1.print(String("SEGUNDOS PARA PASAR"));
  		if(oled_1_autoshow)oled_1.display();
  		oled_1.display();
  		AMARILLO();
  		digitalWrite(25, LOW);
  		digitalWrite(32, LOW);
  		digitalWrite(33, HIGH);
  		TimerFreeTone(26,1000,500);
  		digitalWrite(25, LOW);
  		digitalWrite(32, LOW);
  		digitalWrite(33, LOW);
  		TimerFreeTone(26,500,500);
  		J = (J - 1);
  	}
  	digitalWrite(25, HIGH);
  	digitalWrite(32, LOW);
  	digitalWrite(33, LOW);
  	servo_15.write(0);
  	delay(100);
  	oled_1.clearDisplay();
  	if(oled_1_autoshow)oled_1.display();
  	oled_1.setTextSize(3);
  	oled_1.setTextColor(WHITE);
  	oled_1.setCursor(0,0);
  	oled_1.print(String("PARAR"));
  	if(oled_1_autoshow)oled_1.display();
  	oled_1.display();
  	ROJO();
  	J = I;

}
$abcdeabcde151015202530fghijfghij