- Modul 3
- Komunikasi
- Percobaan 2 Kondisi 4
- 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
a. Rangkaian SimulasiPercobaan ini bertujuan untuk mendemonstrasikan implementasi sistem penghitung digital menggunakan DIP switch sebagai input dan dual seven segment sebagai output, dengan komunikasi serial antar modul Arduino. dengan komponen DIP switch Dual seven segment Dua modul Arduino (Arduino master dan Arduino slave) untuk koneksinya DIP switch terhubung ke input digital Arduino master. Dual seven segment terhubung ke output digital Arduino slave. Komunikasi serial (SPI) terjalin antar modul Arduino melalui pin MOSI, MISO, SCLK, dan SS/CS. DIP switch berfungsi sebagai input digital untuk Arduino master.
Program pada Arduino master dirancang untuk mendeteksi status DIP switch dan menentukan kondisi yang aktif (3 atau 4 switch aktif). Ketika kondisi aktif terpenuhi, Arduino master mengirimkan perintah melalui komunikasi serial SPI ke Arduino slave. Arduino slave menerima perintah dari Arduino master dan mengontrol dual seven segment untuk menampilkan angka yang sesuai dengan kondisi aktif yang terdeteksi.
Arduino Mastera. Flowchart//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. Listing Program
Arduino Master- Arduino Slave
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.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
Senin, 29 April 2024
Langganan:
Posting Komentar (Atom)
Entri yang Diunggulkan
Laporan Akhir Project M4
Laporan Akhir Demo Project [KEMBALI KE MENU SEBELUMNYA] DAFTAR ISI 1. Pendahuluan 2. Tujuan 3. Alat dan Bahan 4. Dasar Teori 5. Percobaan ...
-
TUGAS BESAR [KEMBALI KE MENU SEBELUMNYA] DAFTAR ISI 1. Pendahuluan 2. Tujuan 3. Alat dan Bahan 4. Dasar Teori 5. Percobaan...
-
MODUL 1 DIP SWITCH DAN DOT MATRIX [KEMBALI KE MENU SEBELUMNYA] DAFTAR ISI 1. Pendahuluan 2. Tujuan 3. Alat dan Bahan 4. Dasa...
-
MODUL 1 "Gerbang Logika Dasar & Monostable Multivibrator" [KEMBALI KE MENU SEBELUMNYA] DAFTAR ISI 1. Tujuan 2. ...
Tidak ada komentar:
Posting Komentar