项目作者: 0xMartin

项目描述 :
Graphing calculator using atmega328p
高级语言: C
项目地址: git://github.com/0xMartin/Graphing-Calculator.git
创建时间: 2019-12-19T18:42:01Z
项目社区:https://github.com/0xMartin/Graphing-Calculator

开源协议:Apache License 2.0

下载


Graphing-Calculator

Graphing calculator using atmega328p. Calculator is able to calculating mathematical and logical expressions. As display use nokia 5110 and for input use 4x4 array of micro switches + 1x power switch. Input input voltage of pcb board is 7-35V.

Calculator modes

  • Calculator - calculate value of mathematical expression
  • Grapher - drawing graphs of typed functins f(x)
  • Ploter - ploting graphs of typed functins f(x, y)
  • Logic parser - user type logical expression with variables and constants and than changing value of variables and calculator showing final value of expression

Expression parser

Parser in programed in c++ and work for arduino and desktop aplications (with some corestions). This parser first replace all constants (e, pi) by numbers and after that evaluate all brackets than all unary operations, binary operations and on end sum all particions of expression.

Supported operations

  • Math
    • Default operations: +, -, *, /, ^
    • Brackets: (, ), |
    • Functions: sin, cos, tan, asin, acos, atan, log, log10
      • All functions hava specific ascii code in expression string
      • Its necessary to change the appearance of the character to match the individual functions
        1. #define SIN -128
        2. #define COS -127
        3. #define TG -126
        4. #define ASIN -125
        5. #define ACOS -124
        6. #define ATG -123
        7. #define LOG -122
        8. #define LOG10 -121
        9. #define PI -120
  • Logic
    • Not: !
    • Or: |
    • And: &
    • Equivalency: =

Main part of parser

Arguments are expression and bool logic + aritmetic. If bool logic is true then parser will parsing logic expression or if bool aritmetis is true then parser will parsing aritmetic expression. Both bool can be true in same time.

  1. double ExpressionParser::getValueOfExpression(String expression, bool logic, bool aritmetic) {
  2. if (expression.length() == 0) {
  3. return 0.0;
  4. }
  5. expression = ExpressionParser::replaceVar(&expression, 'e', "2.71828");
  6. expression = ExpressionParser::replaceVar(&expression, PI, "3.14159");
  7. #ifdef DEBUG
  8. Serial.println("IN: " + expression);
  9. #endif
  10. //brackets
  11. ExpressionParser::bracket(&expression, logic, aritmetic);
  12. #ifdef DEBUG
  13. Serial.println("BRACKET: " + expression);
  14. #endif
  15. //unary operators: sin, cos, tg, asin, acos, atg, log, log10, not
  16. ExpressionParser::unaryOperator(&expression);
  17. #ifdef DEBUG
  18. Serial.println("UNARY: " + expression);
  19. #endif
  20. if (aritmetic) {
  21. //default math operation
  22. ExpressionParser::binaryOperations(&expression, '^', false); //power
  23. ExpressionParser::binaryOperations(&expression, '/', true); //divide
  24. ExpressionParser::binaryOperations(&expression, '*', true); //multiply
  25. }
  26. if (logic) {
  27. //logic operatores
  28. ExpressionParser::binaryOperations(&expression, '&', true); //logic and
  29. ExpressionParser::binaryOperations(&expression, '|', true); //logic or
  30. ExpressionParser::binaryOperations(&expression, '=', true); //equivalency
  31. }
  32. #ifdef DEBUG
  33. Serial.println("SUM: " + expression);
  34. #endif
  35. //sum all values and return
  36. return ExpressionParser::sum(&expression);
  37. }

Mode: Calculator

Mode: Grapher

Mode: Ploter

Mode: Logic parser

Circuit schematic

Switches in schematic are represented by resistores. Input voltage must be heigher than 7V. Compunent U3 7805 make 5V for pcb and U4 TS1117BCW33 make 3.3V for display U2 Nokia5110. Resistores R7 and R6 are for input voltage measuring. On right side of schematics is 4x4 button array. Down side are inputs pins for programing (Vcc, Gnd, Tx, Rx, Dtr). Crystal frequency: 16 MHz.

PCB design

One left side is top of pcb and on right is bottom.

Size: 100mm x 56.65mm

Case model

Case of calculator is made for two parts (top and bottom), parts are connected together be four screws.

Top

Bottom

Author

  • Martin Krčma

License

  • This project is licensed under Apache License 2.0 - see the LICENSE.md file for details