Created
August 25, 2013 18:31
-
-
Save rooty/6335457 to your computer and use it in GitHub Desktop.
i2c-arduino-slave
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Wire.h> | |
#define ADDR 128 //адрес устройства | |
void setup() | |
{ | |
Serial.begin(115200);//скорость обмена с компом | |
Wire.begin(ADDR); //определим как ведомый с указанным адресом | |
Wire.onReceive(receive_handler); //ждем данных от мастера, функция возвращает int число байт данных | |
} | |
void loop() {} | |
void receive_handler(int numbytes) | |
{ | |
for (int i=0;i<numbytes;i++) //читаем весь пакет | |
{ | |
Serial.print(Wire.receive()); // принимаем значение и передаем компьютеру | |
} | |
Serial.println(' '); //перенос строки | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment