Arduino를 사용하여 간단한 수학 계산기를 만드는 방법

문제를 제거하기 위해 도구를 사용해보십시오





이 글에서는 일반 계산기보다 훨씬 복잡한 산술 계산을 수행 할 수있는 Arduino를 사용하여 계산기를 구성 할 것입니다.



이 게시물의 모토는 Arduino를 사용하여 계산기를 만드는 것이 아니라 센서 및 기타 주변 장치에서 다양한 복잡한 데이터 해석 및 계산을 수행하는 Arduino의 산술 기능을 보여주기위한 것입니다.

이 재미있는 프로젝트를 위해서는 원하는 USB 케이블과 Arduino 만 있으면됩니다. Arduino IDE의 직렬 모니터를 통해 계산 결과를 얻을 것입니다. C 언어의 기본에 대해 잘 알고 있다면이 프로젝트는 케이크 조각이며 훨씬 더 복잡한 산술 계산을 수행하는 자신 만의 프로그램을 만들 수 있습니다. 여기에서는 Arduino IDE 컴파일러에 내장 된 헤더 파일 #include를 사용하므로 라이브러리를 다운로드 할 필요가 없습니다.



LCD 디스플레이와 키보드를 Arduino에 연결하여 공학용 계산기를 만들 수도 있지만 다른 기사의 주제입니다. 'Turbo C ++'에 익숙하다면 첫 번째 프로그램 중 하나는 두 개의 숫자를 더하는 것입니다. 모든 산술 계산은 컴퓨터의 CPU 내에서 수행됩니다. 그러나 여기에서는 모든 산술 계산이 Arduino 마이크로 컨트롤러에서 수행됩니다. 덧셈, 뺄셈, 나눗셈, 곱셈부터 시작하겠습니다.

여기에 두 개의 변수 a와 b가있는 프로그램이 있습니다.이 두 변수를 사용하여 각각 더하기, 빼기, 곱하기, 나누기 인 '+,-, * /'연산자를 사용하여 위에서 언급 한 계산을 수행 할 수 있습니다.

프로그램:

//-------------------Program Developed by R.Girish---------------//
#include
float a = 500
float b = 105.33
float add
float sub
float divide
float mul
void setup()
{
Serial.begin(9600)
Serial.println('Simple Arduino Calculator:')
Serial.println('n')
Serial.print('a = ')
Serial.println(a)
Serial.print('b = ')
Serial.println(b)
Serial.println('n')
Serial.print('Addition: ')
Serial.print('a + b = ') // add
add=a+b
Serial.println(add)
Serial.print('Multiplication: ')
Serial.print('a * b = ') // multiply
mul=a*b
Serial.println(mul)
Serial.print('Division: ')
Serial.print('a / b = ') // divide
divide=a/b
Serial.println(divide)
Serial.print('Subtraction: ')
Serial.print('a - b = ') // subtract
sub=a-b
Serial.println(sub)
}
void loop() // we need this to be here even though its empty
{
}
//-------------------Program Developed by R.Girish---------------//

산출:

위의 프로그램에서는 십진 함수를 수행하는“Float”를 사용하고 있으며, 시리얼 모니터에서 값을 인쇄하기 위해“Serial.print ()”를 사용하고 나머지 프로그램은 자명합니다. 프로그램에서 변수 a와 b를 자신의 값으로 변경할 수 있습니다.

좀 더 흥미로운 것을 원의 영역으로 이동해 봅시다. 원의 면적 공식은 pi * radius ^ 2 또는 pi 곱하기 반경 제곱입니다. pi의 값은 일정하기 때문에 소수점이 나오는 곳에 pi의 값이 3.14159이므로“float”를 사용하여 프로그램에서 할당해야합니다.

프로그램:

//-------------------Program Developed by R.Girish---------------//
#include
float pi = 3.14159
float radius = 50
float area
void setup()
{
Serial.begin(9600)
Serial.println('Arduino Area Calculator:')
Serial.print('n')
Serial.print('Radius = ')
Serial.print(radius)
Serial.print('n')
area = pi*sq(radius)
Serial.print('The Area of circle is: ')
Serial.println(area)
}
void loop()
{
// we need this to be here even though it is empty
}
//-------------------Program Developed by R.Girish---------------//

산출:

Arduino를 사용한 간단한 수학 계산기

다시 말하지만, 프로그램에서 자신의 값을 변경할 수 있습니다. 우리는 괄호 안의 숫자를 제곱하는“sq ()”를 사용하고 있습니다. 이제 다음 단계로 이동하겠습니다. 이 프로그램에서 우리는 삼각형의 빗변을 계산하기 위해 피타고라스 정리를 사용할 것입니다. 공식은 'hyp = sqrt (sq (base) + sq (height))'또는 (base square + height square)의 제곱근입니다.

프로그램:

//-------------------Program Developed by R.Girish---------------//
#include
float base = 50.36
float height = 45.336
float hyp
void setup()
{
Serial.begin(9600)
Serial.println('Arduino Pythagoras Calculator:')
Serial.print('n')
Serial.print('base = ')
Serial.println(base)
Serial.print('height = ')
Serial.print(height)
Serial.print('n')
hyp=sqrt(sq(base) + sq(height))
Serial.print('The hypotenuse is: ')
Serial.print(hyp)
}
void loop()
{
// we need this to be here even though its empty
}
//-------------------Program Developed by R.Girish---------------//

산출:

프로그램에서 자신의 값으로 기본 및 높이 값을 변경할 수 있습니다. 괄호 안의 제곱근 함수 값을 수행하는 'sqrt ()'를 사용했습니다. 이제 C 언어 과정의 시작 부분 인 피보나치 시리즈에서 배웠을 인기있는 프로그램을 해 보겠습니다.

간단히 말해서 피보나치 시리즈는 다음 숫자를 제공하는 두 개의 이전 숫자를 더한 것입니다. 항상 0, 1로 시작합니다. 예 : 0, 1 따라서 0 + 1 = 1 다음 시리즈는 0, 1, 1입니다. 따라서 1 + 1 = 2입니다. 그래서 다음 시리즈는 0, 1, 1, 2… .. 등입니다. 여기에 작성된 프로그램은 첫 번째 n 번째 자리에 대한 피보나치 수를 찾는 것입니다. 프로그램에서 'n'의 값을 변경하여 원하는 피보나치 수열을 얻을 수 있습니다.

프로그램:

//-------------------Program Developed by R.Girish---------------//
#include
int n=6
int first = 0
int Second = 1
int next
int c
void setup()
{
Serial.begin(9600)
Serial.print('Fibonacci series for first ')
Serial.print(n)
Serial.print(' numbers are:nn')
for ( c = 0 c {
if ( c <= 1 )
next = c
else
{
next = first + Second
first = Second
Second = next
}
Serial.println(next)
}
}
void loop()
{
// put your main code here, to run repeatedly:
}
//-------------------Program Developed by R.Girish---------------//

산출:

그래서 이것은 당신의 두뇌에 충분한 선량을 주었고 하드웨어 주변 장치를 제어하도록 설계된 무언가가 말도 안되는 수학 계산을 수행하고 있다고 혼동했을 것입니다. 그렇다면 혼자가 아닙니다.

수학은 전자 공학에서 중요한 역할을합니다. 그래서 우리 교과서가 수학 방정식으로 가득 차 있고, 우리가 이해하지도 못하는 계산기가 우리를 구하기 위해 오는 지점이고 여기에 있습니다.

Arduino를 사용하는이 간단한 계산기 회로에 대한 질문이 있으면 소중한 의견을 통해 표현할 수 있습니다.




이전 : 0-60V LM317HV 가변 전원 공급 장치 회로 다음 : Piezo에서 전기를 생성하는 방법