#include <TM1637.h>
const int DIO1 = 5;
const int CLK1 = 6;
const int DIO2 = 7;
const int CLK2 = 8;
const int DIO3 = 9;
const int CLK3 = 10;
const int DIO4 = 11;
const int CLK4 = 12;
TM1637 tm1(CLK1, DIO1);
TM1637 tm2(CLK2, DIO2);
TM1637 tm3(CLK3, DIO3);
TM1637 tm4(CLK4, DIO4);
int operand1 = 0;
int operand2 = 0;
int sum = 0;
int difference = 0;
int product = 0;
int quotient = 0;
void setup() {
Serial.begin(9600);
pinMode(2, INPUT_PULLUP);
tm1.init();
tm2.init();
tm3.init();
tm4.init();
tm1.set(BRIGHT_TYPICAL);
tm2.set(BRIGHT_TYPICAL);
tm3.set(BRIGHT_TYPICAL);
tm4.set(BRIGHT_TYPICAL);
}
void loop() {
operand1 = map(analogRead(A0), 0, 1023, 0, 9);
operand2 = map(analogRead(A1), 0, 1023, 0, 9);
Serial.print("Operand A = ");
Serial.println(operand1);
Serial.print("Operand B = ");
Serial.println(operand2);
sum = operand1 + operand2;
difference = operand1 - operand2;
product = operand1 * operand2;
quotient = operand1 / operand2;
if(operand1 == 0)
{
digitalWrite(4, HIGH);
}
else
{
digitalWrite(4, LOW);
}
if(operand2 == 0)
{
digitalWrite(3, HIGH);
}
else
{
digitalWrite(3, LOW);
}
if(digitalRead(2) == LOW)
{
tm4.display(2, (sum / 10) % 10);
tm4.display(3, sum % 10);
tm3.display(2, (difference / 10) % 10);
tm3.display(3, difference % 10);
tm2.display(2, (quotient / 10) % 10);
tm2.display(3, quotient % 10);
tm1.display(2, (product / 10) % 10);
tm1.display(3, product % 10);
}
delay(100);
}