1. Kondisi[Back]
Buatlah led menyala ketika potensiometer 0% dan led padam ketika potensiometer 100%
2. Gambar Rangkaian Simulasi[Back]
3. Video Simulasi[Back]
4. Prinsip Kerja Rangkaian[Back]
MASTER
#include <Wire.h>
#define MASTER_ADDR 9
int analogPin = 0;
int val = 0;
void setup() {
Wire.begin();
}
void loop() {
delay(50);
val = map(analogRead(analogPin), 0, 1023, 255, 1);
Wire.beginTransmission(MASTER_ADDR);
Wire.write(val);
Wire.endTransmission();
}
SLAVE
#include <Wire.h>
#define SLAVE_ADDR 9
int LED = 13;
int rd;
int br;
void setup() {
pinMode(LED, OUTPUT);
Wire.begin(SLAVE_ADDR);
Wire.onReceive(receiveEvent);
Serial.begin(9600);
Serial.println("I2C Slave demo");
}
void receiveEvent(){
rd = Wire.read();
Serial.println(rd);
}
void loop() {
delay(50);
br = map(rd, 1, 255, 100, 2000);
digitalWrite(LED, HIGH);
delay(br);
digitalWrite(LED, LOW);
delay(br);
}
5. Lik Download[Back]
Tidak ada komentar:
Posting Komentar