A day without sunshine is like, you know, night.

Hello Felas! Yah jadi saya menulis postingan ini di tengah malam bersama dengan rintik air hujan yang masih setia menemani dan juga lagu dari  Lasse Lindh, Hush.

Yeay jadi kembali lagi saya bersama postingan saya yang didedikasikan untuk pengerjaan proyek arduino mata kuliah Interaksi Manusia Komputer dan Antarmuka. Pada minggu sebelumnya, saya sudah menceritakan tentang proyek pembuatan kalkulator yang pada minggu lalu belum berhasil dilakukan 100%. Nah minggu ini kami dari RNA kembali mencoba melakukan pengerjaan proyek pembuatan kalkulator ini.

Picture1

Kalkulator yang kami buat dapat mengoperasikan dua bilangan menggunakan satu operasi aritmatika, yaitu penjumlahan, pengurangan, perkalian, atau pembagian. Tampaknya memang sederhana, namun pengerjaan tugas ini melewati lika-liku perjalanan yang cukup panjang. Gimana hasil pengerjaan proyek kali ini? Let’s check it out!

Alat dan Bahan

  1. Arduino Uno
  2. Kabel USB
  3. Breadboard
  4. LCD Display 16×2
  5. Keypad Matriks 4×4
  6. Potensio Meter 10 kOhm
  7. Resistor 220 Ohm
  8. Jumper Male to Male (dibutuhkan dalam jumlah yang cukup banyak)
  9. PC
  10. Arduino IDE

How to make it?

Skema

Berikut adalah skema Fritzing yang digunakan untuk pembuatan proyek kali ini.

lcd_bb

Sumber: https://www.allaboutcircuits.com/projects/simple-arduino-based-calculator/

Source Code

</pre>
<pre class="brush: cpp; title: ; notranslate" title="">#include &amp;amp;amp;lt;Keypad.h&amp;amp;amp;gt;
#include &amp;amp;amp;lt;LiquidCrystal.h&amp;amp;amp;gt;
LiquidCrystal lcd(12,11,5,4,3,2); // Allocate pins to LCD

long num1,num2 ;
double total;
char operation,button;

const byte ROWS = 4;
const byte COLS = 4;

char keys[ROWS][COLS] = {
 {'1','2','3','+'},
 {'4','5','6','-'},
 {'7','8','9','*'},
 {'C','0','=','/'}
};
byte rowPins[ROWS] = {0,1,6,7}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {8,9,10,13}; //connect to the column pinouts of the keypad
Keypad customKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup() {
 // put your setup code here, to run once:
 pinMode(13, OUTPUT);
 digitalWrite(13, LOW);
lcd.begin(16,2);
lcd.setCursor(0,0);
 lcd.print("[-----RNA.-----] ");
 lcd.setCursor(0,1);
 lcd.print(" Presents ");
 delay(5000);
 lcd.setCursor(0,0);
 lcd.print(" Arduino based ");
 lcd.setCursor(0,1);
 lcd.print(" Calculator" );
 delay(5000);
 lcd.clear();// initialize the lcd
}

void loop()
{

 // Loops are convenient for reading key press from keypad
 while(1) // First loop. Here we read keypad and compose our first number. It does so untill we press operation button and break's out of loop or 'C' and it starts from beginning of this loop
 {

 button = customKeypad.getKey(); // Button read
 if (button=='C') // If user wants to resset while he is writing first number
 {
 num1=0;
 num2=0;
 total=0;
 operation=0;
 lcd.clear();
 }

 if (button &amp;amp;amp;gt;='0' &amp;amp;amp;amp;&amp;amp;amp;amp; button &amp;amp;amp;lt;='9') // If user pressed numeric value, 1 character at a time.
 {
 num1 = num1*10 + (button -'0'); // Our numeric values are 0-9 witch means they are in first decade, when we multiply with 10 we basicaly add zero after number,
 // than we add a new number entered to that zero spot. As for (button -'0') this is simple ASCII table "trick" 0...9 in ASCII table are 48 ... 57,
 // so by subtracting '0' from any of them we get their value in decade system ex. char '5' = 53 in decade numeric system minus 48 for zero char gives us value of actual 5,
 // if our previous number was ex. 25 we get 250 by multiplying it with 10 and then we add 5 and we get 255 witch gets printed on LCD.
 lcd.setCursor(0,0); // Select first row on lcd
 lcd.print(num1); // Print current number1
 }
 if (num1 !=0 &amp;amp;amp;amp;&amp;amp;amp;amp; (button=='-' || button=='+' || button=='*' || button=='/')) // If user is done inputing numbers
 {
 operation = button; // operation remembers what mathematical operation user wants on numbers
 lcd.setCursor(0,1); // set cursor to row 2
 lcd.print(operation); // print our operator
 break;
 }

 }

 while(1) // Second while loop, it loops untill user has pressed '=' or 'C'. so it either prints total or ressets program
 {
 if (button =='C'){break;} // This covers case where user pressed operator and still wants to reset
 button = customKeypad.getKey();
 if (button=='C') // Making sure user wants to reset at anytime
 {
 num1=0;
 num2=0;
 total=0;
 operation=0;
 lcd.clear();
 break;
 }
 if (button &amp;amp;amp;gt;='0' &amp;amp;amp;amp;&amp;amp;amp;amp; button &amp;amp;amp;lt;='9') // Getting chars from keypad for number 2
 {
 num2 = num2*10 + (button -'0');
 lcd.setCursor(1,1);
 lcd.print(num2);
 }
 if (button == '=' &amp;amp;amp;amp;&amp;amp;amp;amp; num2 !=0)// If button pressed was '=' its the end of the road. Calls domath() subroutine does calculation and print our results
 {
 domath();

 break;
 }
 }
 while(1)
 {
 // After all is done this loop waits for 'C' key to be pressed so it can reset program and start over.
 if (button =='C'){break;} // This line is side effect of previous loop since if user pressed 'C' it breaks out of previous loop and continues here.So we need to break this one aswell or user would need to press 'C' 2 times
 button = customKeypad.getKey();
 if (button =='C')
 {
 lcd.clear();
 lcd.setCursor(0,0);
 num1=0;
 num2=0;
 total=0;
 operation=0;
 break;
 }
 }

}
void domath() // Simple switch case to pick what operation to do, based on button pressed by user.
{
 switch(operation)
 {
 case '+': // Addition
 total = num1+num2;
 break;

 case '-': // Subtraction
 total = num1-num2;
 break;

 case '/': // Division. Could add error for division by zero, or change line in second loop where it waits for '=' char to if (button == '=' &amp;amp;amp;amp;&amp;amp;amp;amp; num2 != 0) this will halt program untill num2 is not zero and then continue
 total = (float)num1/(float)num2;
 break;

 case '*': // Multiplication
 total = num1*num2;
 break;

 }
 // Based on case selected print our total and
 lcd.setCursor(0,1);
 lcd.print('=');
 lcd.setCursor(1,1);
 lcd.print(total);

}</pre>
<pre>

 

Hasil Pengerjaan

  IMG_20170307_165454IMG_20170307_165734 Dan berikut merupakan video dokumentasi dari proyek kali ini.  

4th Expirement - Calculator with Arduino Uno . . #arduino #uno #calculator #iot

A post shared by RNA (@rnateamid) on

Dalam mengerjakan proyek ini, dibutuhkan waktu yang cukup lama. Kami mengalami masalah di bagian LCD. LCD tidak bisa menyala sama sekali. Kami mencoba memperbaiki source code namun hasilnya nihil. Kemudian kami mencoba menyolder kembali LCD, dan tetap tidak ada tanda-tanda kehidupan untuk LCD. Akhirnya kami mengganti LCD dan… LCD langsung menyala!!!! Okay jadi LCD kami yang bermasalah sehingga pengerjaan proyek ini sedikit memakan waktu untuk troubleshooting.   Okay ternyata sudah malam.  

May you dream of lovely things and wake to find them real!

Even the darkest night will end and the sun will rise

  GOOD NIGHT!   s__2252830

Dibuat oleh :

Rizaldy Al Kautsar (18214026)

Atika Rahmawati (18214044)

Nindy Aditya Dewi (18214052)

Bonus satu lagu pengantar tidur

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s