SHARE
TWEET

Untitled

a guest Mar 18th, 2019 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int led1= 13;
  2. int led2 = 12;
  3. int  x =0 ;
  4.  
  5. void setup()
  6. {
  7.   pinMode(led1,OUTPUT);
  8.   pinMode(led2,OUTPUT);
  9.   Wire.begin(8);                // join i2c bus with address #8
  10.   Wire.onReceive(receiveEvent); // register event
  11.   Serial.begin(9600);           // start serial for output
  12. }
  13.  
  14. void receiveEvent(int bytes)
  15. {
  16.   while (1 < Wire.available())
  17.   {
  18.   x = Wire.read();  // receive byte as an integer
  19.   }
  20. }
  21.  
  22. void loop()
  23. {
  24.  
  25.   if (x == 0){
  26.     digitalWrite(led1, HIGH);
  27.     delay(100);
  28.     digitalWrite(led2, LOW);
  29.     delay(100);
  30.   }
  31.   if (x == 5)
  32.   {
  33.     digitalWrite(led2, HIGH);
  34.     delay(100);
  35.     digitalWrite(led1, LOW);
  36.     delay(100);
  37.   }
  38.  
  39.  
  40. }
  41.      
  42. #define F_CPU 12000000UL
  43. #include "avr/io.h"
  44. #include "util/delay.h"
  45. #include "DataTypes.h"
  46. #include "I2C_M_Reg.h"
  47.  
  48. #define Slave_Address_Write 8
  49. void main(void)
  50. {
  51.     u8 ch = 5;
  52.     I2C_Init();
  53.  
  54.     while(1)
  55.     {
  56.         I2C_Start_Wait(Slave_Address_Write);
  57.         _delay_ms(5);
  58.         I2C_Write(ch);
  59.         /*_delay_ms(10);
  60.         if(ch == 20)
  61.         {
  62.             ch = 0;
  63.         }
  64.         else
  65.         {
  66.  
  67.         }*/
  68.         I2C_Stop();
  69.     }
  70. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top