1. Kondisi [Kembali]
Percobaan 2 Kondisi 13 : Ganti LED menjadi Buzzer, Tambahkan resistor sebelum Buzzer sebesar 1k ohm
2. Gambar Rangkaian Simulasi [Kembali]
#include <SPI.h> //Deklarasi library SPI#define button 2void setup (void) {pinMode(button, INPUT_PULLUP);Serial.begin(115200 ); //Set baud rate 115200digitalWrite(SS, HIGH);// disable Slave SelectSPI.begin ();SPI.setClockDivider(SPI_CLOCK_DIV8); //divide the clock by 8}void loop (void) {char c;int nilai=digitalRead(button);if(nilai==0){digitalWrite(SS, LOW); //enable Slave Select// send test stringfor (const char * p = "Hello, world!\r" ; c = *p; p++){SPI.transfer (c);Serial.print(c);}digitalWrite(SS, HIGH); // disable Slave Selectdelay(1000);}}
- SLAVE
#include <SPI.h>#define led 2char buff [50];volatile byte indx;volatile boolean process;void setup (void) {Serial.begin (115200);pinMode(led, OUTPUT); // have to send on master in so it set as outputSPCR |= _BV(SPE); // turn on SPI in slave modeindx = 0; // buffer emptyprocess = false;SPI.attachInterrupt(); // turn on interrupt}ISR (SPI_STC_vect) // SPI interrupt routine{byte c = SPDR; // read byte from SPI Data Registerif (indx < sizeof buff) {buff [indx++] = c; // save data in the next index in the array buffif (c == '\r') //check for the end of the wordprocess = true;}}void loop (void) {if (process) {digitalWrite(led, HIGH);process = false; //reset the processSerial.println (buff); //print the array on serial monitorindx = 0; //reset button to zerodelay(1000);}else{digitalWrite(led, LOW);}}
6. Link Download [Kembali]
File Rangkaian klik disini
Listing Program Master klik disini
Listing Program Slave klik disini
Datasheet Arduino Uno klik disini
Library Arduino klik disini
Video Simulasi klik disini
HTML klik disini
No comments:
Post a Comment