پروژه ی ساخت ماشین حساب با استفاده از آردوینو
به نام خدا
پروژه ی ساخت ماشین حساب با استفاده از آردوینو

در این پست قصد داریم ماشین حساب با استفاده از آردوینو بسازیم. اما هدف اصلی آشنایی با توانایی های آردوینو در زمینه های محاسبات پردازش می باشد. در این پروژه تنها به یک کابل یو اس بی نیاز داریم. نتایج محاسبات بر روی سیال مانیتور قابل مشاهده است. اگر با مفاهیم زبان C آشنایی دارید این پروژه برای شما بسیار ساده خواهد بود. برای برنامه نویسی از هدر #include<math.h> استفاده می کنیم که نیاز نیست کتابخانه ی آن را دانلود کنید. در ادامه چندین برنامه را تست خواهیم کرد که هرکدام کار خاصی را انجام می دهند.
در برنامه ی زیر دو متغییر داریم که که میتوانیم عمل جمع و تفریق و ضرب و تقسیم را انجام دهیم.
[maxbutton id=”235″ url=”http://avatrobo.ir/wp-content/uploads/2018/06/Calculator.txt” ]
#include<math.h>
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
{
}

در بالا تصویر خروجی یک مثال از برنامه ی بالا را مشاهده می کنید.
در برنامه ی زیر قصد داریم تا محیط دایره را محاسبه کنیم. در اینجا عدد پی را 3.14159 در نظر گرفته ایم.
[maxbutton id=”235″ url=”http://avatrobo.ir/wp-content/uploads/2018/06/Calculator-2.txt” ]
#include<math.h>
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
}
خروجی:

در مثال زیر قصد داریم تا از رابطه ی فیثاغورث استفاده کنیم.
[maxbutton id=”235″ url=”http://avatrobo.ir/wp-content/uploads/2018/06/Calculator-3.txt” ]
#include<math.h>
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
}
خروجی:

در برنامه ی زیر قصد داریم تا دنباله ی فیبوناچی را برای یک تعدا خاص عدد به دست بیاوریم. عدد بعدی در دنباله ی فیبوناچی برابر حاصل جمع دو عدد قبل آن می باشد.
کد برنامه :
[maxbutton id=”235″ url=”http://avatrobo.ir/wp-content/uploads/2018/06/Calculator-4.txt” ]
#include<math.h>
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 < n ; 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:
}
خروجی :

پست های مرتبط
اردیبهشت 9, 1398
اسفند 5, 1397
بهمن 2, 1397
دیدگاهتان را بنویسید