Tugas Pendahuluan Modul 3





1. Kondisi[kembali] 
Percobaan 3 (I2C) , Kondisi ke 5
Rangkailah 5 bual led,buat kelimanya menyala bergantian dengan interval berbanding terbalik dengan nilai potensiometer,

2.  Rangkaian Simulasi[kembali]


3. Flowchart[kembali]


4. Listing Program[kembali]
//MASTER
#include <Wire.h>
#define SLAVE_ADDR 9

int analogPin = A0;
int val1 = 0;
int val2 = 0;
int val3 = 0;
int val4 = 0;
int val5 = 0;

void setup() {
  // put your setup code here, to run once:
Wire.begin();
Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
 delay(50);
  val1 = map(analogRead(A0),0,1023,255,1);

  Wire.beginTransmission(SLAVE_ADDR);
  Wire.write(val1);
  Wire.endTransmission();
  Serial.println(val1);
}


//slave
#include <Wire.h>
#define SLAVE_ADDR 9

int LED1 = 13;
int LED2 = 12;
int LED3 = 11;
int LED4 = 10;
int LED5 = 9;
int rd;
int br1,br2,br3,br4,br5;

void setup() {
  // put your setup code here, to run once:
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED4, OUTPUT);
pinMode(LED5, OUTPUT);
  Wire.begin(SLAVE_ADDR);
  Wire.onReceive(receiveEvent);
  Serial.begin(9600);
  Serial.println("I2C Slave demo");
}

 void receiveEvent(int howMany) {
  rd = Wire.read();
  Serial.println(rd);
}

void loop() {
  // put your main code here, to run repeatedly:
 delay(50);

  br1 = map(rd, 1,255, 1000, 900);
  br2 = map(rd, 1,255, 800, 700);
  br3 = map(rd, 1,255, 600, 500);
  br4 = map(rd, 1,255, 400, 300);
  br5 = map(rd, 1,255, 200, 100);

  digitalWrite(LED1, HIGH);
  digitalWrite(LED2, LOW);
  digitalWrite(LED3, LOW);
  digitalWrite(LED4, LOW);
  digitalWrite(LED5, LOW);
  delay(br1);

  digitalWrite(LED1, LOW);
  digitalWrite(LED2, HIGH);
  digitalWrite(LED3, LOW);
  digitalWrite(LED4, LOW);
  digitalWrite(LED5, LOW);
  delay(br2);

  digitalWrite(LED1, LOW);
  digitalWrite(LED2, LOW);
  digitalWrite(LED3, HIGH);
  digitalWrite(LED4, LOW);
  digitalWrite(LED5, LOW);
  delay(br3);

  digitalWrite(LED1, LOW);
  digitalWrite(LED2, LOW);
  digitalWrite(LED3, LOW);
  digitalWrite(LED4, HIGH);
  digitalWrite(LED5, LOW);
  delay(br4);

  digitalWrite(LED1, LOW);
  digitalWrite(LED2, LOW);
  digitalWrite(LED3, LOW);
  digitalWrite(LED4, LOW);
  digitalWrite(LED5, HIGH);
  delay(br5);

  digitalWrite(LED1, LOW);
  digitalWrite(LED2, LOW);
  digitalWrite(LED3, LOW);
  digitalWrite(LED4, LOW);
  digitalWrite(LED5, LOW);
  delay(1000);

}


5. Video [kembali]





6. Link Download[kembali]

Download listing program 1 di sini
Download listing program 2 di sini
Download file rangkaian di sini
Download video simulasi di sini
Download file html di sini

Tidak ada komentar:

Posting Komentar