forked from bitbank2/sense_hat_unchained
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
70 lines (66 loc) · 1.46 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//
// Sense Hat Unchained Demo Program
// Initializes the sensors and displays various values
// until the joystick is pressed
//
// Copyright (c) 2017 BitBank Software, Inc.
// written by Larry Bank
//
#include <unistd.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <sensehat.h>
//
// Update a simple pattern on the LED matrix
//
void UpdatePattern(void)
{
static int iOffset = 0;
int i, j, x, y;
uint16_t color;
for (i=0; i<64; i++) // do 64 pixels (whole matrix)
{
j = i + iOffset;
color = ((j & 8)>>3) * (j & 31); // blue
color |= (((j & 16)>>4) * (j & 63)<<5); // green
color |= (((j & 32)>>5) * (j & 31)<<11); // red
x = i & 7;
y = (i >> 3);
shSetPixel(x, y, color, 0);
}
shSetPixel(x, y, color, 1); // force an update
iOffset++; // increment for next time through
} /* UpdatePattern() */
int main(int argc, char *argv[])
{
int i;
if (shInit(1) == 0) // Open I2C
{
printf("Unable to open sense hat; is it connected?\n");
return -1;
}
while (1) // run until joystick pressed
{
int t, h, p, x, y, z;
if (shGetTempHumid(&t, &h))
{
printf("T=%d, H=%d\n", t, h);
}
if (shGetPressure(&p, &t))
{
printf("P=%d, T=%d\n", p, t);
}
if (shGetMagneto(&x, &y, &z))
{
printf("accX=%d, accY=%d, accZ=%d\n", x, y, z);
}
for (i=0; i<5; i++) // update pixels 5x as fast as sensor readings
{
// UpdatePattern();
usleep(100000);
}
} // while waiting for joystick press
shShutdown();
return 0;
} /* main() */