TUGAS PENDAHULUAN MODUL 3 PERCOBAAN 2 KONDISI 4
- Modul 3 Komunikasi
- DAFTAR ISI1. Prosedur2. Rangkaian Simulasi dan Prinsip Kerja3. Flowchart dan Listing Program4. Kondisi5. Video Simulasi6. Download File
1. Prosedur [kembali]
- Buatlah rangkaian sesuai dengan kondisi yang telah dipilih
- Buat Program pada software Arduino IDE
- Masukkan program yang telah dibuat pada software Arduino IDE sebagai library Arduino
- Jalankan rangkaian, sesuai dengan kondisi yang diinginkan
2. Rangkaian Simulasi dan Prinsip Kerja [kembali]Pada modul 3, percobaan 2, kondisi 4, kami menggunakan saklar DIP sebagai masukan dan dua segmen tujuh segmen sebagai keluaran.Selain itu juga menggunakan 2 modul, pertama Arduino master sebagai pemberi perintah dan Arduino Slave sebagai penerima/pelaksana perintah.Master Arduino terhubung ke input saklar DIP dan Arduino Slave terhubung ke output tujuh segmen ganda.Pada pengujian ini komunikasi SPI yang digunakan ditandai dengan pin MOSI, MISO, SCLK, SS/CS pada kedua modul yang dihubungkan bersama.Sesuai syarat yang dibutuhkan, jika ada 3 saklar yang aktif, hitung dari 1 sampai 9 pada nomor 1 lalu pindah ke nomor 2, sesuaiif (Slavereceived == 3){for(i=0; i<100; i+=10){setAngka(i);delay(100);}for(i=0; i<10; i++){setAngka(i);delay(100);}Selanjutnya sesuai dengan kondisi kedua yang diminta, 4 switch aktif maka counting 1-9 pada digit 2 lalu pindah pada digit 1, dimana hal ini sesuai dengan program yang telah kita inputkan pada arduinoif (Slavereceived == 4){for(i=0; i<10; i++){setAngka(i);delay(100);}for(i=0; i<100; i+= 10){setAngka(i);delay(100);}3. Flowchart dan Listing Program [kembali]
Arduino Mastera. Listing Program//Master Arduino#include<SPI.h> //Library for SPIint dip[] = {2,3,4,5,6,7,8,9};int dipvalue[] = {};void setup (){Serial.begin(9600); //Starts Serial Communication at Baud Rate 115200for(int i = 0; i < 8; i++){pinMode(dip[i], INPUT_PULLUP);}SPI.begin(); //Begins the SPI commnuicationSPI.setClockDivider(SPI_CLOCK_DIV8); //Sets clock for SPI communication at 8 (16/8=2Mhz)digitalWrite(SS,HIGH); // Setting SlaveSelect as HIGH (So master doesnt connnect with slave)}void loop(void){byte Mastersend;int sw_on = 0;for(int i = 0; i < 8; i++){dipvalue[i] = digitalRead(dip[i]);sw_on = dipvalue[0] + dipvalue[1] + dipvalue[2] + dipvalue[3] + dipvalue[4] + dipvalue[5] + dipvalue[6] + dipvalue[7];}digitalWrite(SS, LOW); //Starts communication with Slave connected to masterMastersend = sw_on;Serial.println(Mastersend);SPI.transfer(Mastersend); //Send the mastersend value to slave also receives value from slavedelay(1000);}- Arduino Slave
//Slave Arduino:#include<SPI.h>#define a 2#define b 3#define c 4#define d 5#define e 6#define f 7#define g 8#define digit1 A1#define digit2 A2volatile boolean received = false;volatile byte Slavereceived;int satuan, puluhan, i;void setup(){Serial.begin(9600);pinMode(a, OUTPUT);pinMode(b, OUTPUT);pinMode(c, OUTPUT);pinMode(d, OUTPUT);pinMode(e, OUTPUT);pinMode(f, OUTPUT);pinMode(g, OUTPUT);pinMode(digit1, OUTPUT);pinMode(digit2, OUTPUT);SPCR |= _BV(SPE); //Turn on SPI in Slave ModeSPI.attachInterrupt(); //Interuupt ON is set for SPI commnucation}ISR (SPI_STC_vect){ //Inerrrput routine functionSlavereceived = SPDR; // Value received from master if store in variable slavereceivedreceived = true; //Sets received as True}void loop(){Serial.println(Slavereceived);if(received){//Logic to SET LED ON OR OFF depending upon the value recerived from masterif (Slavereceived == 4){for(i=0; i<10; i++){setAngka(i);delay(100);}for(i=0; i<100; i+= 10){setAngka(i);delay(100);}}if (Slavereceived == 3){for(i=0; i<100; i+=10){setAngka(i);delay(100);}for(i=0; i<10; i++){setAngka(i);delay(100);}}delay(1000);}}void angka(int xx){if(xx==0){digitalWrite(a,HIGH);digitalWrite(b,HIGH);digitalWrite(c,HIGH);digitalWrite(d,HIGH);digitalWrite(e,HIGH);digitalWrite(f,HIGH);digitalWrite(g,LOW);}if(xx==1){digitalWrite(a,LOW);digitalWrite(b,HIGH);digitalWrite(c,HIGH);digitalWrite(d,LOW);digitalWrite(e,LOW);digitalWrite(f,LOW);digitalWrite(g,LOW);}if(xx==2){digitalWrite(a,HIGH);digitalWrite(b,HIGH);digitalWrite(c,LOW);digitalWrite(d,HIGH);digitalWrite(e,HIGH);digitalWrite(f,LOW);digitalWrite(g,HIGH);}if(xx==3){digitalWrite(a,HIGH);digitalWrite(b,HIGH);digitalWrite(c,HIGH);digitalWrite(d,HIGH);digitalWrite(e,LOW);digitalWrite(f,LOW);digitalWrite(g,HIGH);}if(xx==4){digitalWrite(a,LOW);digitalWrite(b,HIGH);digitalWrite(c,HIGH);digitalWrite(d,LOW);digitalWrite(e,LOW);digitalWrite(f,HIGH);digitalWrite(g,HIGH);}if(xx==5){digitalWrite(a,HIGH);digitalWrite(b,LOW);digitalWrite(c,HIGH);digitalWrite(d,HIGH);digitalWrite(e,LOW);digitalWrite(f,HIGH);digitalWrite(g,HIGH);}if(xx==6){digitalWrite(a,HIGH);digitalWrite(b,LOW);digitalWrite(c,HIGH);digitalWrite(d,HIGH);digitalWrite(e,HIGH);digitalWrite(f,HIGH);digitalWrite(g,HIGH);}if(xx==7){digitalWrite(a,HIGH);digitalWrite(b,HIGH);digitalWrite(c,HIGH);digitalWrite(d,LOW);digitalWrite(e,LOW);digitalWrite(f,LOW);digitalWrite(g,LOW);}if(xx==8){digitalWrite(a,HIGH);digitalWrite(b,HIGH);digitalWrite(c,HIGH);digitalWrite(d,HIGH);digitalWrite(e,HIGH);digitalWrite(f,HIGH);digitalWrite(g,HIGH);}if(xx==9){digitalWrite(a,HIGH);digitalWrite(b,HIGH);digitalWrite(c,HIGH);digitalWrite(d,HIGH);digitalWrite(e,LOW);digitalWrite(f,HIGH);digitalWrite(g,HIGH);}}void setAngka(int xxx) {if (xxx < 10) {puluhan = 0;satuan = xxx;} else if (xxx < 100) {puluhan = xxx / 10;satuan = xxx % 10;}digitalWrite(digit1, LOW);digitalWrite(digit2, HIGH);angka(puluhan);delay(50);digitalWrite(digit1, HIGH);digitalWrite(digit2, LOW);angka(satuan);delay(50);}- b. Flow Chart
Arduino Master- Arduino Slave
4. Kondisi [kembali]
Jika 3 switch aktif maka counting 1-9 pada digit 1 lalu pada digit 2, jika 4 switch aktif maka counting 1-9 pada digit 2 lalu pada digit 1.5. Video Simulasi [kembali]
6. Download File [kembali]Download HTML klik disiniDownload Rangkaian Proteus klik disiniDownload Program Arduino Master klik disiniDownload Program Arduino Slave klik disini - Download Video klik disini
- Download Datasheet 7 segment klik disini
- Download Datasheet Arduino klik disini