Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <unistd.h>
  3.  
  4. #include <pigpio.h>
  5.  
  6. #define I2C_ADDR 0x48
  7.  
  8. int main(void) {
  9. if (gpioInitialise() < 0) return 1;
  10.  
  11. int handle = i2cOpen(1, I2C_ADDR, 0);
  12.  
  13. unsigned char value;
  14. char aout = 128;
  15. unsigned char command[2];
  16.  
  17. command[1] = aout;
  18. command[0] = 0x40 | (0 & 0x03);
  19.  
  20. while (1) {
  21. i2cWriteDevice(handle, &command, 2);
  22. usleep(2000);
  23. value = i2cReadByte(handle);
  24. printf("%d\n", value);
  25. // sleep(1);
  26. }
  27.  
  28. i2cClose(handle);
  29. gpioTerminate();
  30.  
  31. return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement