MODUL III

Percobaan 2 Kondisi 8



 

Modul 1 Percobaan 1 Kondisi 18

Tambahkan resistor sebelum Button sebesar 1k ohm

2. Gambar Rangkaian Simulasi [kembali]

  
  Rangkaian percobaan 2










Rangkaian yang disusun terdiri dari 2 buah Arduino, lalu untuk outputan dari pin 2 dihubungkan ke button, kaki 7 dihubungkan ke kaki LED begitu pula pada bagian Arduino Slave. Untuk pin 13 12 11 sendiri saling dihubungkan karena pada pin tersebut kita gunakan sebagai data transfer antar mikroprosesor, dimana ada pin MOSI, pin MISO dan pin SCLK yang saling terhubung. untuk sinyal Clock sendiri digunakan untuk sinkronisasi antar arduino.

dan program yang ditulis sebagai berikut :

//GERINANDA
//2010953004
//KEL 11

// Percobaan 1 Kondisi 16
////Ubah button menjadi saklar SPST

//MASTER

#include<SPI.h>                             //Library for SPI
#define LED 7          
#define ipbutton 2
int buttonvalue;
int x;
void setup (void)
{
  Serial.begin(9600);                   //Starts Serial Communication at Baud Rate 9600
  pinMode(ipbutton,INPUT);                //Sets pin 2 as input
  pinMode(LED,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
}
void loop(void)
{
  byte Mastersend,Mastereceive;          
  buttonvalue = digitalRead(ipbutton);   //Reads the status of the pin 2
  if(buttonvalue == HIGH)                //Logic for Setting x value
  {
    x = 1;
  }
  else
  {
    x = 0;
  }
  digitalWrite(SS, LOW);                  //Starts communication with Slave
  Mastersend = x;                            
  Mastereceive=SPI.transfer(Mastersend); //Send the mastersend value to slave
  if(Mastereceive == 1)                   //Logic for setting the LED output
  {
    digitalWrite(LED,HIGH);              //Sets pin 7 HIGH
    Serial.println("Master LED ON");
  }
  else
  {
   digitalWrite(LED,LOW);               //Sets pin 7 LOW
   Serial.println("Master LED OFF");
  }
  delay(1000);
}

//GERINANDA
//2010953004
//KEL 11

// Percobaan 1 Kondisi 16
////Ubah button menjadi saklar SPST

//MASTER

//SPI SLAVE (ARDUINO)
//SPI COMMUNICATION BETWEEN TWO ARDUINO
//CIRCUIT DIGEST
//Pramoth.T
#include<SPI.h>
#define LEDpin 7
#define buttonpin 2
volatile boolean received;
volatile byte Slavereceived,Slavesend;
int buttonvalue;
int x;
void setup()
{
  Serial.begin(9600);
  pinMode(buttonpin,INPUT);               // Setting pin 2 as INPUT
  pinMode(LEDpin,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(LEDpin,HIGH);         //Sets pin 7 as HIGH LED ON
        Serial.println("Slave LED ON");
      }else
      {
        digitalWrite(LEDpin,LOW);          //Sets pin 7 as LOW LED OFF
        Serial.println("Slave LED 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
  delay(1000);
}
}


5. Link Download [kembali]

Rangkaian Simulasi Proteus : Klik Disini...
File HTML : Klik Disini...
Video Rangkaian : Klik Disini...
Program Arduino Master : Klik Disini...
Program Arduino Slave : Klik Disini...
Library Arduino UNO : Klik Disini...
Data sheet Arduino UNO : Klik Disini...
Data sheet LED : Klik Disini...
Data sheet RES : Klik Disini...
Data sheet BUTTON : Klik Disini...


\

Tidak ada komentar:

Posting Komentar

 BAHAN PORESENTASI UNTUK MATAKULIAH KIMIA 2020 Kelompok 14 Bab 8. Hubungan Periodik Antar Unsur OLEH GERINANDA 2010953004 ...