-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArtemis.pde
110 lines (91 loc) · 2.37 KB
/
Artemis.pde
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include <AikoDeviceMCP320x.h>
#include <AikoEvents.h>
#include <Wire.h>
#include <OneWire.h>
#include "ADXL330.h"
#include "DS1307.h"
#include "DS18B20.h"
#include "MPX4101A.h"
using namespace Aiko;
Device::MCP320x adc5v(47);
Device::MCP320x adc3v(48);
ADXL330 accelerometer(adc3v);
MPX4101A mapSensor(adc5v);
DS1307 clock;
OneWire oneWire(2);
DS18B20 temperatureSensor(oneWire);
void reportNodeName() {
Serial.println("(nodeName= artemis_1)");
}
void readClock() {
clock.read();
Serial.print("(clock= ");
if (clock.hour_ < 10) Serial.print('0');
Serial.print((int)clock.hour_);
if (clock.minute_ < 10) Serial.print('0');
Serial.print((int)clock.minute_);
if (clock.second_ < 10) Serial.print('0');
Serial.print((int)clock.second_);
Serial.println(")");
}
void readAccelerometer() {
int x = accelerometer.readX();
int y = accelerometer.readY();
int z = accelerometer.readZ();
Serial.print("(acceleromter_x= ");
Serial.print(x);
Serial.println(")");
Serial.print("(acceleromter_y= ");
Serial.print(y);
Serial.println(")");
Serial.print("(acceleromter_z= ");
Serial.print(z);
Serial.println(")");
}
void readMapSensor() {
Serial.print("(barometer= ");
Serial.print(mapSensor.readPressure());
Serial.println(")");
}
void readLDRs() {
Serial.print("(light_a= ");
Serial.print(analogRead(0));
Serial.println(")");
Serial.print("(light_b= ");
Serial.print(analogRead(1));
Serial.println(")");
}
void readVoltage() {
float voltage = (float)analogRead(7) * (5.0 / 1024.0);
Serial.print("(voltage= ");
Serial.print(voltage);
Serial.println(")");
}
void readTemperature() {
temperatureSensor.read();
Serial.print("(temperature= ");
Serial.print(temperatureSensor.temperature());
Serial.println(")");
temperatureSensor.startConversion();
}
void setup() {
clock.second_ = 0;
clock.minute_ = 1;
clock.hour_ = 2;
clock.dayOfWeek_ = 3;
clock.dayOfMonth_ = 4;
clock.month_ = 5;
clock.year_ = 6;
clock.set();
Serial.begin(9600);
Events.addHandler(reportNodeName, 1000);
Events.addHandler(readClock, 1000);
Events.addHandler(readAccelerometer, 100);
Events.addHandler(readMapSensor, 100);
Events.addHandler(readLDRs, 100);
Events.addHandler(readVoltage, 100);
Events.addHandler(readTemperature, 1000);
}
void loop() {
Events.loop();
}