Ganti potensiometer dengan push button dan led dengan motor DC. Jika push button ditekan maka motor berputar searah jarum jam. Dan jika push button dilepas maka motor berhenti.
2.Gambar Rangkaian simulasi (kembali)
3.Flowchart (kembali)
4.Koding Program (kembali)
MASTER
#include <Wire.h>
#define SLAVE_ADDR 9
int butt=12;
int val = 0;
void setup() {
pinMode(butt, INPUT);
Wire.begin();
}
void loop() {
delay(50);
val=digitalRead(butt);
Wire.beginTransmission(SLAVE_ADDR);
Wire.write(val);
Wire.endTransmission();
// put your main code here, to run repeatedly:
}
#define SLAVE_ADDR 9
int butt=12;
int val = 0;
void setup() {
pinMode(butt, INPUT);
Wire.begin();
}
void loop() {
delay(50);
val=digitalRead(butt);
Wire.beginTransmission(SLAVE_ADDR);
Wire.write(val);
Wire.endTransmission();
// put your main code here, to run repeatedly:
}
#include <Wire.h>
#define SLAVE_ADDR 9
int in1 = 9;
int in2 = 10;
int rd;
void setup() {
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
Wire.begin(SLAVE_ADDR);
Wire.onReceive(receiveEvent);
Serial.begin(9600);
Serial.println("I2C Slave demo");
digitalWrite(in1,HIGH);
}
void receiveEvent() {
rd = Wire.read();
Serial.println(rd);
}
void loop() {
if(rd==0){
digitalWrite(in1,HIGH);
digitalWrite(in2,LOW);
delay(100);
}
else{
digitalWrite(in1,LOW);
digitalWrite(in2,LOW);
delay(100);
}
}
Download Video disini
Download Rangkaian disini
Downlaod Program disini
Download Html disini
Tidak ada komentar:
Posting Komentar