#include <U8g2lib.h>
//#include <RTClib.h>
//#include <WiFi.h>
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
#define tamanoMax 7
const int ledPin = 2;
int numeroEntero = 1234;
char CantChar[tamanoMax];
char UMChar[tamanoMax];
char CodChar[tamanoMax];
char DescCodChar[tamanoMax];
char PedPartChar[tamanoMax];
char UbicChar[tamanoMax];
char EncabezadoChar[tamanoMax];
//char logo_SPick[tamanoMax];
String textoCant;
String textoPedPart = "";
String textoDescCod = "";
String textoCod = "";
String textoUM = "";
String textoUbic = "";
int pedido = 127615;
int partida;
int partidas;
int caracteresNumero;
int idCod;
// const char* ssid = "Lean Sigma";
// const char* password = "ramram00";
int tipoSurtido = -1;
// const char* idGoogleSheets = "1ZexG-Y7FEVVQv_2L22V1BclBQX2OQ4SFqg3s7UFnfvM";
String tipoEncabezado = "PedPart";
void setup() {
Serial.begin(115200);
Serial.println("********************************************************");
Serial.println("********** SPick -> El almacén inteligente ***********");
Serial.println("********************************************************");
Serial.println("Conectando a WiFi...");
// WiFi.begin(ssid, password);
// while (WiFi.status() != WL_CONNECTED) {
// delay(1000);
// Serial.print(".");
// }
// Serial.println("");
// Serial.println("Conectado a WiFi");
Serial.println("-------------------------------------------------------------");
pinMode(ledPin, OUTPUT);
u8g2.begin();
u8g2.setFont(u8g2_font_8bitclassic_tf); // Establecer la fuente del texto
u8g2.setFontMode(1); // Modo de texto transparente
u8g2.setFontDirection(0); // Dirección del texto
}
//-------------------------------------------------------------------
void regeneraDisplay(){
u8g2.clearBuffer(); // Limpia OLED
// Muestra Encabezado
u8g2.setFont(u8g2_font_6x13_t_cyrillic); // Establecer la fuente del pedido y partida
if (tipoEncabezado == "PedPart"){
Serial.println("Se muestra PedPart: "+ textoPedPart);
textoPedPart = "Ped: " + String(pedido) + " p"+ String(partida) + "/"+ String(partidas);
char PedPartChar[textoPedPart.length() + 1];
textoPedPart.toCharArray(PedPartChar, textoPedPart.length() + 1);
u8g2.drawStr(2, 9, PedPartChar); //leyendaDescCod); // Escribir CHAR Pedido Partida en la pantalla
tipoEncabezado = "DescCod";
}
else{
Serial.println("Se muestra descripción: " + textoDescCod);
textoPedPart = "Ped: " + String(pedido) + " p"+ String(partida) + "/"+ String(partidas);
char DescCodChar[textoDescCod.length() + 1];
textoDescCod.toCharArray(DescCodChar, textoDescCod.length() + 1);
u8g2.drawStr(2, 9, DescCodChar); //leyendaDescCod); // Escribir CHAR Pedido Partida en la pantalla
tipoEncabezado = "PedPart";
}
// Muestra Código y UM
u8g2.setFont(u8g2_font_logisoso16_tr); // Establecer fuente del Código y su UM
// Muestra UM
textoUM.toCharArray(UMChar, textoUM.length()+1);
u8g2.drawStr(90, 60, UMChar); // Escribir textoUM en la pantalla
// Muestra Código
textoCod.toCharArray(CodChar, textoCod.length()+1);
u8g2.drawStr(2, 32, CodChar);
//
u8g2.setFont(u8g2_font_logisoso16_tr); // Establecer fuente del Código y su UM
textoUM.toCharArray(UMChar, textoUM.length()+1);
textoCod.toCharArray(CodChar, textoCod.length()+1);
u8g2.drawLine(1,11,120,11);
u8g2.setFont(u8g2_font_logisoso16_tr); // Establecer fuente del Código y su textoUM
// Conversion de string a char
Serial.println(textoCant);
textoCant.toCharArray(CantChar , textoCant.length() + 1);
u8g2.setFont(u8g2_font_logisoso26_tf); // Establecer la fuente de la cantidad a surtir
u8g2.drawStr(2, 64, CantChar); // Escribir el número aleatorio texto en la pantalla
u8g2.sendBuffer();
}
//-------------------------------------------------------------------
void displaySPick(){
u8g2.clearBuffer(); // Limpia OLED
digitalWrite (ledPin, LOW);
u8g2.setFont(u8g2_font_logisoso26_tf); // Establecer la fuente del texto
u8g2.drawStr(20, 45, "SPick!"); // Escribir texto en la pantalla
u8g2.sendBuffer(); // Enviar el buffer a la pantalla
delay(500);
u8g2.clearBuffer(); // Limpia OLED
u8g2.setFont(u8g2_font_logisoso16_tf); // Establecer la fuente del texto
u8g2.drawStr(1, 25, "El surtido"); // Escribir texto en la pantalla
u8g2.drawStr(1, 55, "inteligente!"); // Escribir texto en la pantalla
u8g2.sendBuffer(); // Enviar el buffer a la pantalla
delay(500);
u8g2.clearBuffer(); // Limpia OLED
digitalWrite (ledPin, HIGH);
}
//-------------------------------------------------------------------
void sigPartida(){
displaySPick();
// Muestra Pedido y Partida en OLED ----------------------------------------------------------------------
partida++;
if (partida > partidas){
pedido++;
partida = 1;
partidas = random(9) + 1;
}
textoPedPart = "Ped: " + String(pedido) + " p"+ String(partida) + "/"+ String(partidas);
// Genera el Código de manera aleatoria y asocia su UM
idCod = random(14) + 1;
switch (idCod) {
case 1:
textoCod = "COD_01";
textoDescCod = "Descripción COD_01";
textoUbic = "[A-"+String(idCod)+"]";
textoUM = "pz";
break;
case 2:
textoCod = "COD_02";
textoDescCod = "Descripción COD_02";
textoUbic = "[A-"+String(idCod)+"]";
textoUM = "par";
break;
case 3:
textoCod = "COD_03";
textoDescCod = "Descripción COD_03";
textoUbic = "[A-"+String(idCod)+"]";
textoUM = "m";
break;
case 4:
textoCod = "COD_04";
textoDescCod = "Descripción COD_04";
textoUbic = "[A-"+String(idCod)+"]";
textoUM = "pz";
break;
case 5:
textoCod = "COD_05";
textoDescCod = "Descripción COD_05";
textoUbic = "[A-"+String(idCod)+"]";
textoUM = "jgo";
break;
case 6:
textoCod = "COD_06";
textoDescCod = "Descripción COD_06";
textoUbic = "[A-"+String(idCod)+"]";
textoUM = "pz";
break;
case 7:
textoCod = "COD_07";
textoDescCod = "Descripción COD_07";
textoUbic = "[A-"+String(idCod)+"]";
textoUM = "m2";
break;
case 8:
textoCod = "COD_08";
textoDescCod = "Descripción COD_08";
textoUbic = "[A-"+String(idCod)+"]";
textoUM = "Jgo";
break;
case 9:
textoCod = "COD_09";
textoDescCod = "Descripción COD_09";
textoUbic = "[A-"+String(idCod)+"]";
textoUM = "m3";
break;
case 10:
textoCod = "COD_10";
textoDescCod = "Descripción COD_10";
textoUbic = "[A-"+String(idCod)+"]";
textoUM = "par";
break;
case 11:
textoCod = "COD_11";
textoDescCod = "Descripción COD_11";
textoUbic = "[A-"+String(idCod)+"]";
textoUM = "pz";
break;
case 12:
textoCod = "COD_12";
textoDescCod = "Descripción COD_12";
textoUM = "kg";
break;
case 13:
textoCod = "COD_13";
textoDescCod = "Descripción COD_13";
textoUbic = "[A-"+String(idCod)+"]";
textoUM = "oz";
break;
case 14:
textoCod = "COD_14";
textoDescCod = "Descripción COD_14";
textoUbic = "[A-"+String(idCod)+"]";
textoUM = "yrd";
break;
case 15:
textoCod = "COD_15";
textoDescCod = "Descripción COD_15";
textoUbic = "[A-"+String(idCod)+"]";
textoUM = "lb";
break;
default:
// statements
break;
}
// Genera la cantidad a surtir de 1 to 10000 -------------------------------------------
numeroEntero = random(10000);
textoCant = String(numeroEntero);
caracteresNumero = textoCant.length();
Serial.println("Pedido: "+ String(pedido));
Serial.println("Partida: "+ String(partida) + " de "+ String(partidas));
Serial.println("Código: "+ textoCod);
Serial.print("Cant Solicitada: "+ textoCant);
Serial.println(" "+textoUM);
regeneraDisplay();
}
//-------------------------------------------------------------------
void loop() {
//if(WiFi.status()== WL_CONNECTED){
// Muestra la Descrupción del artículo por 3 segundos y luego muestra el PedPart
if (touchRead(T9) < 50) {
regeneraDisplay();
}
// Surtido Nulo
if (touchRead(T8) < 50) {
tipoSurtido = 0;
Serial.println("Cant Surtida: 0 " + textoUM);
Serial.println("--------------------------");
sigPartida();
}
// Surtido Parcial
if (touchRead(T4) < 50) {
Serial.println("Cant Surtida: " + String(numeroEntero - 1) + " " + textoUM);
Serial.println("--------------------------");
tipoSurtido = 2;
sigPartida();
}
// Surtido Completo
if (touchRead(T5) < 50) {
Serial.println("Cant Surtida: " + String(numeroEntero) + " " + textoUM);
Serial.println("--------------------------");
tipoSurtido = 1;
sigPartida();
}
delay(1000);
//}
}
//-------------------------------------------------------------------