Pages: [1]   Go Down
Author Topic: Arduino I2C Slave  (Read 741 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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);
    
  
}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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();
 
}
« Last Edit: March 20, 2013, 11:34:55 pm by playagood » Logged

Pages: [1]   Go Up
Jump to: