Buatlah led menyala ketika potensiometer 0% dan led padam ketika potensiometer 100%
2. Rangkaian Simulasi
[Kembali]
4. Listing Program [Kembali]
//MASTER
#include <Wire.h>
#define MASTER_ADDR 9
int analogPin = 0; int val = 0;
void setup() {
// put your setup code here, to run once:
Wire.begin();
}
void loop() {
// put your main code here, to run repeatedly:
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() {
// put your setup code here, to run once:
pinMode(LED, OUTPUT);
Wire.begin(SLAVE_ADDR);
Wire.onReceive(receiveEvent);
}
void receiveEvent(){
rd = Wire.read();
}
void loop() {
// put your main code here, to run repeatedly:
delay(50);
br = map(rd, 1, 255, 100, 2000);
if (br == 2000){
delay(1000);
digitalWrite(LED, HIGH);
}else if (br == 100){
delay(1000);
digitalWrite(LED, LOW);
}
}
File rangkaian download
Listing program download
File video download
File html download
Tidak ada komentar:
Posting Komentar