MCPcopy Create free account
hub / github.com/DexterInd/GoPiGo3 / main

Function main

Software/C/Examples/i2c.cpp:31–53  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29void exit_signal_handler(int signo);
30
31int main(){
32 signal(SIGINT, exit_signal_handler); // register the exit function for Ctrl+C
33
34 GPG.detect(); // Make sure that the GoPiGo3 is communicating and that the firmware is compatible with the drivers.
35
36 GPG.set_grove_type(GROVE_1, GROVE_TYPE_I2C);
37 i2c_struct_t I2C1;
38 I2C1.address = 0x24;
39 I2C1.length_read = 3;
40 I2C1.length_write = 1;
41 uint8_t s = 0;
42 while(true){
43 I2C1.buffer_write[0] = s;
44 int error = GPG.grove_i2c_transfer(GROVE_1, &I2C1);
45 printf("Error: %d bytes: %d %d %d\n", error, I2C1.buffer_read[0], I2C1.buffer_read[1], I2C1.buffer_read[2]);
46 if(s == 0){
47 s = 1;
48 }else{
49 s = 0;
50 }
51 usleep(50000);
52 }
53}
54
55// Signal handler that will be called when Ctrl+C is pressed to stop the program
56void exit_signal_handler(int signo){

Callers

nothing calls this directly

Calls 3

detectMethod · 0.80
set_grove_typeMethod · 0.45
grove_i2c_transferMethod · 0.45

Tested by

no test coverage detected