LAPORAN AKHIR 2 praktikum up & uc
1. Prosedur [Kembali]
1. Susun semua komponen.
2. Buat program menggunakan aplikasi Arduino IDE.
3. Unggah program ke Arduino setelah selesai.
4. Jalankan program pada simulasi dan uji dengan modul.
2. Buat program menggunakan aplikasi Arduino IDE.
3. Unggah program ke Arduino setelah selesai.
4. Jalankan program pada simulasi dan uji dengan modul.
2. Hardware dan Diagram Blok [Kembali]
3. Rangkaian Simulasi dan Prinsip Kerja [Kembali]
4. Flowchart dan Listing Program [Kembali]
Flowchart
Listing Program master
#include <Wire.h>
#define SLAVE_ADDRESS 9 // Slave Arduino address
#define BUTTON1 2 // Pin for the push button
#define BUTTON2 3
int buttonState1 = 0;
int buttonState2 = 0;
int buttonPrevState1 = 0;
int buttonPrevState2 = 0;
unsigned int counter = 0;
unsigned int count = 0;
void setup() {
Wire.begin(); // Initialize I2C communication
pinMode(BUTTON1, INPUT_PULLUP); // Set button pin as input with internal pull-up resistor
pinMode(BUTTON2, INPUT_PULLUP);
Serial.begin(9600); // Initialize serial communication for debugging
}
void loop() {
buttonState1 = digitalRead(BUTTON1);
buttonState2 = digitalRead(BUTTON2);
if (buttonState2 != buttonPrevState2){
if(buttonState2 == LOW){
count++;
}
delay(50);
}
buttonPrevState2 = buttonState2;
if(count > 3){
count = 0;
}
if(count % 2 == 0){
if (buttonState1 != buttonPrevState1) {
if (buttonState1 == LOW) {
// Button is pressed
counter++;
Wire.beginTransmission(SLAVE_ADDRESS);
Wire.write(counter); // Send command to the slave
Wire.endTransmission();
}
delay(50); // Debouncing delay
}
buttonPrevState1 = buttonState1;
if(counter > 3){
counter = 0;
}
}else if(count % 3 == 0){
Wire.endTransmission();
}
Serial.print(count); Serial.println(counter);
}
listing program slave
#include <Wire.h>
#define LED_COUNT 8
#define LED_PIN_START 2 // Start pin for the LEDs
void setup() {
Serial.begin(9600);
Wire.begin(9); // Initialize I2C communication as Slave with address 9
Wire.onReceive(receiveEvent); // Register event for receiving data
for (int i = LED_PIN_START; i < LED_PIN_START + LED_COUNT; i++) {
pinMode(i, OUTPUT); // Set LED pins as output
}
}
void loop() {
}
void receiveEvent(int numBytes) {
unsigned int command = Wire.read(); // Read incoming command from master
Serial.println(command);
delay(500);
if (command == 1) {
// Turn all LEDs ON
for (int i = LED_PIN_START; i < LED_PIN_START + LED_COUNT; i++) {
digitalWrite(i, HIGH);
}
} else if (command == 2) {
// Turn all LEDs OFF
for (int i = LED_PIN_START; i < LED_PIN_START + LED_COUNT; i++) {
digitalWrite(i, LOW);
}
} else if (command == 3) {
// Blink all LEDs
for (int j = 0; j < 5; j++) { // Repeat the blinking 5 times
for (int i = LED_PIN_START; i < LED_PIN_START + LED_COUNT; i++) {
digitalWrite(i, HIGH);
delay(1000);
}
delay(500); // Delay for ON state
for (int i = LED_PIN_START; i < LED_PIN_START + LED_COUNT; i++) {
digitalWrite(i, LOW);
delay(1000);
}
delay(500); // Delay for OFF state
}
}
}
5. Kondisi [Kembali]
percobaan 5 Modul 3
6. Video Simulasi [Kembali]
7. Link Download [Kembali]
Download HTML [Klik di sini]
Download file rangkaian [Klik di sini]
Download video rangkaian [Klik di sini]
Download program Arduino [Klik di sini]
Download datasheet Arduino [Klik di sini]
Komentar
Posting Komentar