Arduino calculator in Proteus!

Поділитися
Вставка
  • Опубліковано 7 вер 2024
  • Hi guys to see more PIC microcontroller projects visit my channel or my website:
    elecroplanet.b...
    And to check more arduino projects visit:
    sirboatengonli...

КОМЕНТАРІ • 3

  • @loldaily4241
    @loldaily4241 4 місяці тому

    Thank you!

  • @EasyElectronics2
    @EasyElectronics2  4 місяці тому

    // By HomeMade Electronics
    // Subscribe to my channel ua-cam.com/channels/8isJR_71x1wIfw6jB106pg.html
    // Visit website sirboatengonline.com for more tutorial videos
    // Like, share, and leave a comment if you need help. Thank you!
    #include
    #include // Download the Keypad library from github.com/Chris--A/Keypad
    const byte ROWS = 4;
    const byte COLS = 4;
    // Define the Keymap
    char keys[ROWS][COLS] = {
    {'7', '8', '9', 'D'},
    {'4', '5', '6', 'C'},
    {'1', '2', '3', 'B'},
    {'*', '0', '#', 'A'}
    };
    byte rowPins[ROWS] = {A0, A1, A2, A3};
    byte colPins[COLS] = {10, 9, 8, 7};
    Keypad kpd = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
    LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
    long Num1, Num2, Number;
    char key, action;
    boolean result = false;
    void setup() {
    lcd.begin(16, 2);
    lcd.print(" Uno Calculator");
    lcd.setCursor(0, 1);
    lcd.print(" HomeMade Tech ");
    delay(2000);
    lcd.clear();
    }
    void loop() {
    // Store pressed key value in a char container
    key = kpd.getKey();
    if (key != NO_KEY)
    DetectButtons();
    if (result == true)
    CalculateResult();
    DisplayResult();
    }
    void DetectButtons() {
    lcd.clear();
    if (key == '*') {
    Number = Num1 = Num2 = 0;
    result = false;
    }
    if (key == '1') {
    Serial.println("Button 1");
    if (Number == 0)
    Number = 1;
    else
    Number = (Number * 10) + 1; // If pressed twice
    }
    // Similar code for keys '4', '7', '0', '2', '5', '8', '3', '6', '9'
    // Detecting Buttons on Column 4
    if (key == 'A' || key == 'B' || key == 'C' || key == 'D') {
    Num1 = Number;
    Number = 0;
    if (key == 'A') {
    action = '+';
    }
    if (key == 'B') {
    action = '-';
    }
    if (key == 'C') {
    action = '*';
    }
    if (key == 'D') {
    action = '/';
    }
    delay(100);
    }
    }
    void CalculateResult() {
    if (action == '+')
    Number = Num1 + Num2;
    // Similar code for '-', '*', '/'
    }
    void DisplayResult() {
    // Set the cursor to column 0, line 1 and display the results
    lcd.setCursor(0, 0);
    lcd.print(Num1);
    lcd.print(action);
    lcd.print(Num2);
    if (result == true) {
    lcd.print(" =");
    lcd.print(Number);
    }
    // Set the cursor to column 0, line 1 and display the result
    lcd.setCursor(0, 1);
    lcd.print(Number);
    }

  • @bobbi5858
    @bobbi5858 4 місяці тому

    Gj