So I realised that making this code would be useless, As I wasn't going to use this sketch, since I was going to use more than one arduino. So can someone tell me what I'm doing wrong here? basically I want to have one arduino have a sensor and another arduino have an rgb led. When the sensor on the arduino is triggered. the led on the other one changes color. This is the code I put in for the sensor arduino
#include <Wire.h>
#define LIGHT_ADDR 9
#define ANSWERSIZE 5
#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
SoftwareSerial mySoftwareSerial(11, 10); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);
int analogPin = A0;
int val = A0;
void setup() {
mySoftwareSerial.begin(9600);
Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));
if (!myDFPlayer.begin(mySoftwareSerial)) { //Use softwareSerial to communicate with mp3.
Serial.println(F("Unable to begin:"));
Serial.println(F("1.Please recheck the connection!"));
Serial.println(F("2.Please insert the SD card!"));
while(true);
}
Serial.println(F("DFPlayer Mini online."));
Wire.begin();
Serial.begin(9600);
Serial.println("I2C Sensor");
}
void loop() {
repeatedly:
delay(50);
val = analogRead(analogPin);
Wire.beginTransmission(LIGHT_ADDR);
Wire.write(val);
Wire.endTransmission();
}
and this is the code i put in for the light arduino
#include <Wire.h>
#define LIGHT_ADDR 9
int RED = 7;
int GREEN = 6;
int BLUE = 5;
int rd;
int br;
void setup() {
pinMode(RED, OUTPUT);
pinMode(GREEN, OUTPUT);
pinMode(BLUE, OUTPUT);
Wire.begin(LIGHT_ADDR);
from master
Wire.onReceive(receiveEvent);
Serial.begin(9600);
Serial.println("I2C Light Demonstration");
}
void receiveEvent() {
rd = Wire.read();
Serial.println(rd);
}
void loop() {
delay(50);
br = analogRead(rd)
digitalWrite(RED, HIGH);
digitalWrite(GREEN, LOW);
digitalWrite(BLUE, HIGH);
}
What am I doing Wrong?