嗨,我想通过 I2C 将 arduino pro mini 连接到我的 AtTiny85。
arduino 应该告诉服装打开或关闭 LED。arduino 设法打开了我的衣服上的 LED,但它永远不会熄灭。
我不知道为什么?
这是我的主从代码:
掌握:
#include <Wire.h>
#define device (1)
void setup() {
// put your setup code here, to run once:
Wire.begin();
}
void loop() {
// put your main code here, to run repeatedly:
Wire.beginTransmission(device);
Wire.write(1);
Wire.endTransmission();
delay(2000);
Wire.write(0);
Wire.endTransmission();
delay(2000);
}
奴隶:
#include <TinyWireS.h>
#include <usiTwiSlave.h>
#define output (4)
#define I2C_SLAVE_ADDR (1)
void setup() {
// put your setup code here, to run once:
TinyWireS.begin(I2C_SLAVE_ADDR);
pinMode(output, OUTPUT);
}
volatile byte msg = 0;
void loop() {
if(TinyWireS.available())
msg = TinyWireS.receive();
if(msg == 1)
digitalWrite(output, HIGH);
else if(msg == 0)
digitalWrite(output, LOW);
else
msg = 0;
}