Skip to content

Instantly share code, notes, and snippets.

@rooty
Created August 25, 2013 18:31
Show Gist options
  • Save rooty/6335457 to your computer and use it in GitHub Desktop.
Save rooty/6335457 to your computer and use it in GitHub Desktop.
i2c-arduino-slave
#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