#define INPUT_PIN1 2
#define INPUT_PIN2 3
#define INPUT_PIN3 4
#define INPUT_PIN4 5
#define OUTPUT_PIN1 6
#define OUTPUT_PIN2 7
#define OUTPUT_PIN3 8
#define OUTPUT_PIN4 9
#define OUTPUT_PIN5 10
#define OUTPUT_PIN6 11
#define OUTPUT_PIN7 12
void setup()
{
pinMode(INPUT_PIN1, INPUT);
pinMode(INPUT_PIN2, INPUT);
pinMode(INPUT_PIN3, INPUT);
pinMode(INPUT_PIN4, INPUT);
pinMode(OUTPUT_PIN1, OUTPUT);
pinMode(OUTPUT_PIN2, OUTPUT);
pinMode(OUTPUT_PIN3, OUTPUT);
pinMode(OUTPUT_PIN4, OUTPUT);
pinMode(OUTPUT_PIN5, OUTPUT);
pinMode(OUTPUT_PIN6, OUTPUT);
pinMode(OUTPUT_PIN7, OUTPUT);
Serial.begin(9600);
}
void loop()
{
int A= digitalRead(INPUT_PIN1);
int B = digitalRead(INPUT_PIN2);
int C = digitalRead(INPUT_PIN3);
int D = digitalRead(INPUT_PIN4);
int AI,BI,CI,DI,SUM;
Serial.print("A: ");
Serial.print(A);
Serial.print(" | B: ");
Serial.print(B);
Serial.print(" | C: ");
Serial.print(C);
Serial.print(" | D: ");
Serial.println(D);
AI=A*1;
BI=B*2;
CI=C*4;
DI=D*8;
Serial.print("AI: ");
Serial.print(AI);
Serial.print(" | BI: ");
Serial.print(BI);
Serial.print(" | CI: ");
Serial.print(CI);
Serial.print(" | DI: ");
Serial.println(DI);
SUM=AI+BI+CI+DI;
Serial.print(" | SUM: ");
Serial.println(SUM);
if(SUM<8)
{
digitalWrite(OUTPUT_PIN1, HIGH);
}
if(SUM>7)
{
if(SUM<16 && SUM>7)
{
digitalWrite(OUTPUT_PIN6, HIGH);
digitalWrite(OUTPUT_PIN7, HIGH);
}
if(SUM==15)
{
digitalWrite(OUTPUT_PIN2, HIGH);
}
else
{
digitalWrite(OUTPUT_PIN1, LOW);
}
}
if(SUM==1)
{
digitalWrite(OUTPUT_PIN3, HIGH);
digitalWrite(OUTPUT_PIN4, LOW);
digitalWrite(OUTPUT_PIN5, LOW);
}
if(SUM==2)
{
digitalWrite(OUTPUT_PIN3, LOW);
digitalWrite(OUTPUT_PIN4, HIGH);
digitalWrite(OUTPUT_PIN5, LOW);
}
if(SUM==3)
{
digitalWrite(OUTPUT_PIN3, HIGH);
digitalWrite(OUTPUT_PIN4, HIGH);
digitalWrite(OUTPUT_PIN5, LOW);
}
if(SUM==4)
{
digitalWrite(OUTPUT_PIN3, LOW);
digitalWrite(OUTPUT_PIN4, LOW);
digitalWrite(OUTPUT_PIN5, HIGH);
}
if(SUM==5)
{
digitalWrite(OUTPUT_PIN3, HIGH);
digitalWrite(OUTPUT_PIN4, LOW);
digitalWrite(OUTPUT_PIN5, HIGH);
}
if(SUM==6)
{
digitalWrite(OUTPUT_PIN3, LOW);
digitalWrite(OUTPUT_PIN4, HIGH);
digitalWrite(OUTPUT_PIN5, HIGH);
}
if(SUM==7)
{
digitalWrite(OUTPUT_PIN3, HIGH);
digitalWrite(OUTPUT_PIN4, HIGH);
digitalWrite(OUTPUT_PIN5, HIGH);
}
if(SUM==8)
{
digitalWrite(OUTPUT_PIN3, HIGH);
digitalWrite(OUTPUT_PIN4, LOW);
digitalWrite(OUTPUT_PIN5, LOW);
}
if(SUM==9)
{
digitalWrite(OUTPUT_PIN3, LOW);
digitalWrite(OUTPUT_PIN4, HIGH);
digitalWrite(OUTPUT_PIN5, LOW);
}
if(SUM==10)
{
digitalWrite(OUTPUT_PIN3, HIGH);
digitalWrite(OUTPUT_PIN4, HIGH);
digitalWrite(OUTPUT_PIN5, LOW);
}
if(SUM==11)
{
digitalWrite(OUTPUT_PIN3, LOW);
digitalWrite(OUTPUT_PIN4, LOW);
digitalWrite(OUTPUT_PIN5, HIGH);
}
if(SUM==12)
{
digitalWrite(OUTPUT_PIN3, HIGH);
digitalWrite(OUTPUT_PIN4, LOW);
digitalWrite(OUTPUT_PIN5, HIGH);
}
if(SUM==13)
{
digitalWrite(OUTPUT_PIN3, LOW);
digitalWrite(OUTPUT_PIN4, HIGH);
digitalWrite(OUTPUT_PIN5, HIGH);
}
if(SUM==14)
{
digitalWrite(OUTPUT_PIN3, HIGH);
digitalWrite(OUTPUT_PIN4, HIGH);
digitalWrite(OUTPUT_PIN5, HIGH);
}
if(SUM==15)
{
digitalWrite(OUTPUT_PIN3, HIGH);
digitalWrite(OUTPUT_PIN4, HIGH);
digitalWrite(OUTPUT_PIN5, HIGH);
}
// Wait for a short period before reading again
delay(500); // Delay in milliseconds
}