File tree 3 files changed +36
-6
lines changed
examples/Ports/gravity_demo
3 files changed +36
-6
lines changed Original file line number Diff line number Diff line change @@ -641,6 +641,15 @@ const int* GravityPlug::getAxes() {
641
641
return data.w ;
642
642
}
643
643
644
+ char GravityPlug::temperature () {
645
+ send ();
646
+ write (0x08 );
647
+ receive ();
648
+ char temp = read (1 ) - 60 ;
649
+ stop ();
650
+ return temp;
651
+ }
652
+
644
653
/* * Select the channel on the multiplexer.
645
654
* @param channel A number between 0..15.
646
655
*/
Original file line number Diff line number Diff line change @@ -535,6 +535,9 @@ class GravityPlug : public DeviceI2C {
535
535
// / Get accelleration data from GravityPlug.
536
536
// / @return An array with 3 integers. (x,y,z) respectively.
537
537
const int * getAxes ();
538
+ // / Read out the temperature (only for BMA150, not the older BMA020)
539
+ // / @return temp, in half deg C steps, from -30C to +50C (i.e. times 2)
540
+ char temperature ();
538
541
};
539
542
540
543
// / Interface for the Input Plug - see http://jeelabs.org/ip
Original file line number Diff line number Diff line change @@ -8,24 +8,42 @@ PortI2C myBus (1);
8
8
GravityPlug sensor (myBus);
9
9
MilliTimer measureTimer;
10
10
11
+ struct {
12
+ int axes[3 ];
13
+ int temp;
14
+ } payload;
15
+
11
16
void setup () {
12
17
Serial.begin (57600 );
13
18
Serial.println (" \n [gravity_demo]" );
14
- rf12_initialize (7 , RF12_868MHZ, 5 );
19
+
20
+ if (sensor.isPresent ()) {
21
+ Serial.print (" sensor version " );
22
+ sensor.send ();
23
+ sensor.write (0x01 );
24
+ sensor.receive ();
25
+ Serial.println (sensor.read (1 ), HEX);
26
+ sensor.stop ();
27
+ }
28
+
29
+ rf12_initialize (7 , RF12_868MHZ, 42 );
15
30
sensor.begin ();
16
31
}
17
32
18
33
void loop () {
19
34
if (measureTimer.poll (1000 )) {
20
- const int * p = sensor.getAxes ();
35
+ memcpy (payload.axes , sensor.getAxes (), sizeof payload.axes );
36
+ payload.temp = sensor.temperature ();
21
37
22
- rf12_sendNow (0 , p, 3 * sizeof *p );
38
+ rf12_sendNow (0 , &payload, sizeof payload );
23
39
24
40
Serial.print (" GRAV " );
25
- Serial.print (p[0 ]);
41
+ Serial.print (payload.axes [0 ]);
42
+ Serial.print (' ' );
43
+ Serial.print (payload.axes [1 ]);
26
44
Serial.print (' ' );
27
- Serial.print (p[ 1 ]);
45
+ Serial.print (payload. axes [ 2 ]);
28
46
Serial.print (' ' );
29
- Serial.println (p[ 2 ] );
47
+ Serial.println (payload. temp );
30
48
}
31
49
}
You can’t perform that action at this time.
0 commit comments