Modul 3 perc 2








Gambar Button


GambarLED


















MASTER :

#include<SPI.h>
#define SLAVE_ADDR 9

bool state, lastState;

int analogPin = 0;
int val = 0;

void setup() {
  pinMode(analogPin, INPUT_PULLUP);
  pinMode(analogPin, OUTPUT);
  pinMode(SS, OUTPUT);
  digitalWrite(SS, HIGH);
  SPI.begin();
  SPI.setClockDivider(SPI_CLOCK_DIV8);
}
void loop() {
  state = digitalRead(analogPin);
  if(state != lastState){
  delay(50);
  val = map(analogRead(analogPin), 0, 1023, 255, 1);

  Serial.print(val);
  }
}

SLAVE :


#include<SPI.h>
#define SLAVE_ADDR 9

int LED = 13;
int rd;
int br;

void setup() {
  pinMode(LED, OUTPUT);
  SPCR |= _BV(SPE);
  SPI.attachInterrupt();

}
void loop() {

  delay(50);
  br = map(rd, 1, 255, 100, 2000);

  digitalWrite(LED, HIGH);
  delay(br);
  digitalWrite(LED, LOW);
  delay(br);

}






6. Link Download  [Kembali]


Tidak ada komentar:

Posting Komentar