babyyoda_

Master_ESP

Jun 27th, 2021 (edited)
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Wire.h>
  2. //#define I2C_SLAVE_1_ADDR  1
  3. #define I2C_SLAVE_2_ADDR  2
  4.  
  5. void setup() {
  6.   Wire.begin(); // join i2c bus (address optional for master)
  7.   Serial.begin(9600);
  8.   Serial.print("Ready");
  9. }
  10.  
  11. char x = 0;
  12.  
  13. void loop() {
  14.   if (Serial.available() > 0) {
  15.  
  16.     x = Serial.read();
  17.  
  18.     if (x == '0') {
  19.       Wire.beginTransmission(2); // transmit to device #8
  20.       Wire.write('0');              // sends one byte
  21.       Wire.endTransmission();    // stop transmitting
  22.     }
  23.     if (x == '1') {
  24.       Wire.beginTransmission(2); // transmit to device #8
  25.       Wire.write('1');              // sends one byte
  26.       Wire.endTransmission();    // stop transmitting
  27.     }
  28.     if (x == '2') {
  29.       Wire.beginTransmission(2); // transmit to device #8
  30.       Wire.write('2');              // sends one byte
  31.       Wire.endTransmission();    // stop transmitting
  32.     }
  33.     if (x == '3') {
  34.       Wire.beginTransmission(2); // transmit to device #8
  35.       Wire.write('3');              // sends one byte
  36.       Wire.endTransmission();    // stop transmitting
  37.     }
  38.   }
  39. }
Add Comment
Please, Sign In to add comment