TP 1 MODUL 2
1. Kondisi[Back]
percobaan 2 kondisi 10
Ganti LED menjadi Buzzer
2. Gambar Rangkaian Simulasi[Back]
Rangkaian percobaan 1 kondisi 1
Listing Program:
//MASTER
#include<SPI.h> //Library for SPI
#define buzzer 7
#define button 2
int buttonvalue;
int x;
void setup (void)
{
Serial.begin(115200); //Starts Serial Communication at Baud Rate 115200
pinMode(button,INPUT); //Sets pin 2 as input
pinMode(buzzer,OUTPUT); //Sets pin 7 as Output
SPI.begin(); //Begins the SPI commnuication
SPI.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,Mastereceive;
buttonvalue = digitalRead(button); //Reads the status of the pin 2
if(buttonvalue == HIGH) //Logic for Setting x value (To be sent to slave) depending upon input from pin 2
{
x = 1;
}
else
{
x = 0;
}
digitalWrite(SS, LOW); //Starts communication with Slave connected to master
Mastersend = x;
Mastereceive=SPI.transfer(Mastersend); //Send the mastersend value to slave also receives value from slave
if(Mastereceive == 1) //Logic for setting the LED output depending upon value received from slave
{
digitalWrite(buzzer,HIGH); //Sets pin 7 HIGH
Serial.println("Master Buzzer ON");
}
else
{
digitalWrite(buzzer,LOW); //Sets pin 7 LOW
Serial.println("Master Buzzer OFF");
}
}
//SLAVE
#include <SPI.h>
#define buzzerpin 7
#define buttonpin 2
volatile boolean received;
volatile byte Slavereceived,Slavesend;
int buttonvalue;
int x;
void setup()
{
Serial.begin(115200);
pinMode(buttonpin,INPUT); // Setting pin 2 as INPUT
pinMode(buzzerpin,OUTPUT); // Setting pin 7 as OUTPUT
pinMode(MISO,OUTPUT); //Sets MISO as OUTPUT (Have to Send data to Master IN
SPCR |= _BV(SPE); //Turn on SPI in Slave Mode
received = false;
SPI.attachInterrupt(); //Interuupt ON is set for SPI commnucation
}
ISR (SPI_STC_vect) //Inerrrput routine function
{
Slavereceived = SPDR; // Value received from master if store in variable slavereceived
received = true; //Sets received as True
}
void loop()
{ if(received) //Logic to SET LED ON OR OFF depending upon the value recerived from master
{
if (Slavereceived==1)
{
digitalWrite(buzzerpin,HIGH); //Sets pin 7 as HIGH LED ON
Serial.println("Slave Buzzer ON");
}
else
{
digitalWrite(buzzerpin,LOW); //Sets pin 7 as LOW LED OFF
Serial.println("Slave Buzzer OFF");
}
buttonvalue = digitalRead(buttonpin); // Reads the status of the pin 2
if (buttonvalue == HIGH) //Logic to set the value of x to send to master
{
x=1;
}
else
{
x=0;
}
Slavesend=x;
SPDR = Slavesend; //Sends the x value to master via SPDR
}
}
3. Video Simulasi[Back]
4. Prinsip Kerja Rangkaian[Back]
pada rangkaian digunakan komponen yaitu arduino sebagai pengendali dan perangkat komunikasi antar arduino. push button sebagai input dan buzzer sebagai output.
pada rangkaian dilakukan komunikasi PSI yang menghubungkan MISO antar arduino. prinsip kerja dari rangaian ini. apabila push button pada sisi master di tekan maka arus akan mengalir dari sumber yang terdapar pada sisi slave menuju ground sisi master sehingga mengaktifkan buzzer pada sisi slave dan apabila push button pada sisi slave ditekan maka arus mengalir dari sisi master menuju ground pada sisi slave sehingga mengaktifkan buzzer pada sisi slave. hal ini terjadi karena adanya komunikasi antar perangkat dengan jenis komunikasi SPI. kinerja dari rangkaian ini sesuai dengan logika yang diberikan pada program diatas.
5. Download[Back]
-File html download file
-File Rangkaian download file
-File Program download file
-File Video download file
-Datasheet Push Button Download File
-Datasheet Arduino UNO Download File
-Datasheet Resistor download file
-Datasheet Arduino UNO download file
Tidak ada komentar:
Posting Komentar