#include <LiquidCrystal.h>
LiquidCrystal lcd(11,10,5,4,3,2);
float c1 = 0;
float c2 = 0;
float vysledok;
bool plus = true;
bool minus = true;
bool krat = true;
bool deleno = true;
void setup()
{
pinMode(A5, INPUT);
pinMode(A4, INPUT);
pinMode(A3, INPUT_PULLUP);
pinMode(A2, INPUT_PULLUP);
pinMode(A1, INPUT_PULLUP);
pinMode(A0, INPUT_PULLUP);
lcd.begin(20,4);
}
void loop()
{
lcd.setCursor(0,0);
lcd.println("Zadajte hodnoty: ");
c1 = analogRead(A5) / 10;
lcd.setCursor(0, 1);
lcd.print("Cislo 1: ");
lcd.print(c1);
lcd.print(" ");
c2 = analogRead(A4) / 10;
lcd.setCursor(0, 2);
lcd.print("Cislo 2: ");
lcd.print(c2);
lcd.print(" ");
lcd.setCursor(0, 3);
operacia();
}
void operacia()
{
if(digitalRead(A0) == LOW && plus == true)
{
plus = false;
vysledok = c1 + c2;
lcd.print("Vysledok: ");
lcd.print(vysledok);
lcd.print(" ");
}
if(digitalRead(A0) == HIGH)
plus = true;
if(digitalRead(A1) == LOW && minus == true)
{
minus = false;
vysledok = c1 - c2;
lcd.print("Vysledok: ");
lcd.print(vysledok);
lcd.print(" ");;
}
if(digitalRead(A1) == HIGH)
minus = true;
if(digitalRead(A2) == LOW && krat == true)
{
krat = false;
vysledok = c1 * c2;
lcd.print("Vysledok: ");
lcd.print(vysledok);
lcd.print(" ");
}
if(digitalRead(A2) == HIGH)
krat = true;
if(digitalRead(A3) == LOW && deleno == true)
{
deleno = false;
if (c2 != 0)
{
vysledok = c1 / c2;
lcd.print("Vysledok: ");
lcd.print(vysledok, 6);
lcd.print(" ");
}
else
{
lcd.print("Math error ");
}
}
if(digitalRead(A3) == HIGH)
deleno = true;
}