Тема: PCF8576 + Arduino
Показать сообщение отдельно
Старый 24.05.2013, 20:44   #6
macau
Старший Пользователь
 
Регистрация: 22.10.2012
Регион: 78, 98
Сообщений: 758
macau is just really nicemacau is just really nicemacau is just really nicemacau is just really nice
По умолчанию

#include <Wire.h>
#define ADDR 0x88 //адрес устройства
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(), HEX); // принимаем значение и передаем компьютеру
}
Serial.println(' '); //перенос строки

}
или

#include <Wire.h>

void setup()
{
Wire.begin(0x44); // join i2c bus with address #4
Wire.onReceive(receiveEvent); // regis-ter event
Serial.begin(9600); // start serial for output
}

void loop()
{
delay(100);
}

// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany)
{
while(1 < Wire.available()) // loop through all but the last
{
// char c = Wire.read(); // receive byte as a character
// Serial.print(c); // print the character
}
int x = Wire.read(); // receive byte as an integer
Serial.println(x, HEX);
Serial.println(x, BIN); // print the integer
}

в зависимости от тупости железки работает либо тот, либо тот.
еще для тинси есть интересный проект: bus-ninja
macau вне форума   Ответить с цитированием