//El Perceptron como AND,OR,NOT,XOR embebido
//04-03-2024
//JEAL, SBA, AFRI, RJTO
//Declaracion de Variables
float hand,hor,hnot,hxor, hnand;
float sesand,sesor,sesnot,sesxor,sesnand;
int saland= 32;
int salor= 33;
int salnot= 25;
int salxor= 26;
int yand, yor, ynot, yxor, ynand;
int land, lnand;
byte la,lb;
#include <LiquidCrystal.h>
LiquidCrystal lcd (22,21,5,18,23,19); //pines a conectar la LCD al NODE-MCU
void setup() {
Serial.begin (9600);
lcd.begin(0*27, 20 ,4);
pinMode (la, INPUT);
pinMode (lb, INPUT);
pinMode (saland,OUTPUT);
pinMode (salor,OUTPUT);
pinMode (salnot,OUTPUT);
pinMode (salxor,OUTPUT);
}
void loop() {
//--------------------------------------------------------------
la = digitalRead (4);
lb = digitalRead (0);
//Declaracion de Sesgos
sesand = (-3);
sesor = (-1);
sesnot = (1);
sesxor = (-3);
sesnand= (3);
//Mensaje de Compuerta AND
lcd.setCursor (0,0);
lcd.print("AND:");
lcd.setCursor (4,0);
lcd.print(la);
lcd.setCursor (6,0);
lcd.print(lb);
lcd.setCursor (8,0);
lcd.print(sesand);
lcd.setCursor (15,0);
lcd.print(yand);
//Mensaje Compuerta OR
lcd.setCursor (0,1);
lcd.print("OR:");
lcd.setCursor (4,1);
lcd.print(la);
lcd.setCursor (6,1);
lcd.print(lb);
lcd.setCursor (8,1);
lcd.print(sesor);
lcd.setCursor (15,1);
lcd.print(yor);
//Mensaje Compuerta NOT
lcd.setCursor (20,0);
lcd.print("NOT:");
lcd.setCursor (24,0);
lcd.print(la);
lcd.setCursor (29,0);
lcd.print(sesnot);
lcd.setCursor (35,0);
lcd.print(ynot);
//Mensaje Compuerta XOR
lcd.setCursor (20,1);
lcd.print("XOR:");
lcd.setCursor (24,1);
lcd.print(la);
lcd.setCursor (26,1);
lcd.print(lb);
lcd.setCursor (28,1);
lcd.print(sesxor);
lcd.setCursor (35,1);
lcd.print(yxor);
//----------------------------------------------------------------
//h= xw + b
//y= escalon unitario (h)
hand = ((la*(2) + lb*(2)) + sesand);
hor = ((la*(1)+lb*(1))+sesor);
hnot = ((la*(-2))+sesnot);
hnand = ((la*(-2)+lb*(-2))+sesnand);
hxor = ((ynand*(2) + yor*(2)) + sesxor);
//-------------------------------------------------------
if (hand >= 0){
yand= 1;
digitalWrite (saland, HIGH); }
else
{
yand= 0;
digitalWrite(saland, LOW);
}
//------------------------------------------------------
if (hor >= 0){
yor= 1;
digitalWrite (salor, HIGH); }
else
{
yor= 0;
digitalWrite(salor, LOW);
}
//--------------------------------------------------------
if (hnot < 0){
ynot= 1;
digitalWrite (salnot, HIGH); }
else
{
ynot= 0;
digitalWrite(salnot, LOW);
}
//--------------------------------------------------------
if (hxor >= 0){
yxor= 1;
digitalWrite (salxor, HIGH); }
else
{
yxor= 0;
digitalWrite(salxor, LOW);
}
//-------------------------------------------------------
if (hnand >= 0){
ynand= 1;
}
else
{
ynand= 0;
}
//---------------------------------------------
Serial.print (ynand);
Serial.print (" ");
Serial.print (yor);
Serial.print(" ");
Serial.println (hxor);
Serial.print (" ");
Serial.println (yxor);
delay (100);
}