Hello,
My name is Yi-Chun and i'm making a project for my school.
I'm fairly new to arduino and dont understand that much of the language.
I want to make i2c communication but with multiple inputs and outputs so i can save wire's in my project because the second arduino is going to be placed on a risky part.
Can someone help me with this? i already made it work with 1 input and 1 output but i dont know where to start with multiple in and outputs.
Thanks !
#include <Wire.h>
#define BUTTON 10
#define ADDRESS 42
void setup() {
Serial.begin(112500); // start serial for output
pinMode(BUTTON, INPUT);
digitalWrite(BUTTON, HIGH);
Wire.begin();
}
boolean last_state = HIGH;
void loop() {
if (digitalRead(BUTTON) != last_state){
last_state = digitalRead(BUTTON);
Serial.println("Start");
Wire.beginTransmission(ADDRESS);
Serial.println("Beginning transmission");
Wire.write(last_state);
Serial.println("Sent Data");
Wire.endTransmission();
Serial.println("Ended transmission");
}
}
For master arduino
#include <Wire.h>
#define LED_OUT 7
#define ADDRESS 42
void setup() {
pinMode(LED_OUT, OUTPUT);
digitalWrite(LED_OUT, LOW);
Serial.begin(112500);
Wire.begin(ADDRESS);
Wire.onReceive(receiveEvent);
}
void loop() {
}
void receiveEvent(int howMany){
while (Wire.available() > 0){
boolean b = Wire.read();
Serial.print(b, DEC);
digitalWrite(LED_OUT, !b);
}
Serial.println();
}
Project_ropbot_slave.ino (409 Bytes)
master_project_robot.ino (582 Bytes)