Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Example By ArduinoAll
- // Arduino ตัวที่ 2 ใช้รับข้อมูล ที่ Arduino ตัวที่ 1 ส่งมา
- #include <Wire.h>
- int led = 13;
- int x = 0;
- void setup() {
- Wire.begin(9); // เริ่มสื่อสารแบบ I2C กำหนด address คือ 9
- Wire.onReceive(receiveEvent); // เมื่อมีข้อมูลส่งมาให้ทำในฟังก์ชั่นนี้ register event
- Serial.begin(9600);
- pinMode(led, OUTPUT);
- }
- void loop() {
- delay(100);
- }
- void receiveEvent( int bytes )
- {
- x = Wire.read(); // อ่านค่าที่รับเข้ามา
- Serial.println(x);
- if (x == 0) {
- digitalWrite(led, LOW);
- }
- if (x == 1) {
- digitalWrite(led, HIGH);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement