Go Down

Topic: Arduino I2C Slave (Read 835 times) previous topic - next topic

playagood

Hi,
    I trying to connect 2 Arduino via I2C. I'm wondering if this code is correct for the slave device. (For the master device, I using Arduino/Labview) :

I would like to dim light pin 9 on the Arduino slave from Labview. Is that code ok?  Thank you

Arduio slave code:

Code: [Select]

#include <Wire.h>

byte IWire1 =0;
int OLight1= 9;

void setup()
{
 Wire.begin(4);                // join i2c bus with address #4
 Wire.onReceive(receiveEvent); // register event
 pinMode(OLight1, OUTPUT);

}

void loop()
{
 delay(100);
}

void receiveEvent(int howMany)
{
IWire1 = Wire.read();
analogWrite(OLight1, IWire1);
   
 
}

playagood

#1
Mar 21, 2013, 05:11 am Last Edit: Mar 21, 2013, 05:34 am by playagood Reason: 1
Ok, I change it and it works now. The light brightess change from low to high in a good flow except that from 240 to 255, it increases significantly.  I don't know why?


Arduino code:

Code: [Select]
#include <Wire.h>


byte IWire1 =0;
int OLight1= 9;


void setup()
{
 Wire.begin(4);                // join i2c bus with address #4
 Wire.onReceive(receiveEvent); // register event
 pinMode(OLight1, OUTPUT);

}


void loop()
{
 analogWrite(OLight1, IWire1);
}



void receiveEvent(int howMany)

{


IWire1 = Wire.read();

}

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy