พึ่งหัดเล่น arduion มันแปลงหน่วยยังไง

Started by 007pro, February 24, 2015, 07:25:59 AM

Previous topic - Next topic


narin510

ประกาศตัวแปรเป็น float ครับ 
ผมยก function does math มาให้ดูตามข้างล่างนี้
+ - x / ยกกำลัง sin cos tan
code ตัวเต็มจะเป็นการสร้างเครื่องคิดเลขด้วย Arduino
แจกฟรีและศึกษาได้จากที่นี่  http://www.instructables.com/id/Arduino-Calculator/step7/Code/


//////////////////////FUNCTION DOES MATH/////////////////////////////////////////
float executefunction(int _function, float _firstnumber, float _secondnumber) 
{
    float _output;
    switch (_function)
    {
    case 0:
      _output = _firstnumber + _secondnumber;
      break;
    case 1:
      _output = _firstnumber - _secondnumber;
      break;
    case 2:
      _output = _firstnumber * _secondnumber;
      break;
    case 3:
      if(_secondnumber != 0) {_output = _firstnumber / _secondnumber;}
      break;
    case 4:
      _output = pow(_firstnumber, _secondnumber);
      _output= round(_output);
      break;
    case 5:
      _output = pow(_firstnumber, 2);
      break;
    case 6:
      _output = sin(_firstnumber);
      break;
    case 7:
      _output = cos(_firstnumber);
      break;
    case 8:
      _output = tan(_firstnumber);
      break;
    case 9:
      break;
    }
    return _output;
}


narin510

* แปลงหน่วย เป็น Kg ก็เอา 1,000 หารครับ
หรือเอา 10 ยกกำลัง 3 เข้าไปหารค่าที่จะแปลง

sunmoon

ขอบคุณครับ มาเก็บความรู้ปรกติเขียน หาร ไม่เคยเช็คค่า = 0 ก่อนเลย จะทำให้เป็นนิสัยครับ

man2520

ขอบคุณครับ จะลองเอาไปใช้ดูครับ