#include <math.h>
#define THERMO_ADDR 0X4D
int main() {
printf("Arduino connected\n");
uint8_t *config =
wireRead(THERMO_ADDR, 0xAC, 1);
config[1] |= 0x0D;
while(1) {
uint8_t *bytes =
wireRead(THERMO_ADDR, 0xAA, 2);
double temperature_c = 0;
temperature_c += bytes[0];
for(int i = 0; i < 4; i++) {
temperature_c += ((bytes[1] >> 4+i) & 0x01) / pow(2, i+1);
}
printf("%.04f F\n", temperature_c * 9/5.0 + 32);
free(bytes);
}
return 0;
}
void wireWrite(uint8_t addr, uint8_t reg, uint8_t num_bytes, uint8_t *data)
Definition: ModmataC.c:340
int connectArduino(char *port, int baudRate, int id)
Definition: ModmataC.c:93
uint8_t * wireRead(uint8_t addr, uint8_t reg, int num_bytes)
Definition: ModmataC.c:362
void closeConnection()
Definition: ModmataC.c:51
void wireBegin()
Definition: ModmataC.c:308
void delay(int millis)
Definition: ModmataC.c:56