forked from RobotZwrrl/ClydeDev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClydeAfraidDark.cpp
More file actions
executable file
·54 lines (33 loc) · 1.08 KB
/
ClydeAfraidDark.cpp
File metadata and controls
executable file
·54 lines (33 loc) · 1.08 KB
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
/**
* Copyright (c) 2014 Erin Kennedy and Fabule Fabrications Inc, All rights reserved.
* Licensed under GPL v3, see license.txt for more info.
*/
#include "ClydeAfraidDark.h"
ClydeAfraidDark::ClydeAfraidDark(uint8_t m) : ClydeModule(ID_LOW, ID_HIGH) {
debug_stream = &Serial;
LOG_LEVEL = ERROR_;
ClydeModule::determineModulePins(m);
apin = ClydeModule::apin();
dpin = ClydeModule::dpin();
light = 0;
}
bool ClydeAfraidDark::init() {
if(LOG_LEVEL <= DEBUG) *debug_stream << "Beginning Afraid Dark module initialisation" << endl;
// check the id of the module to see that it matches
bool passed = ClydeModule::checkModuleId();
if(!passed) {
if(LOG_LEVEL <= WARN) *debug_stream << "Error initialising the Afraid Dark module. Failed to read ID value." << endl;
return false;
}
pinMode(dpin, INPUT);
digitalWrite(dpin, LOW);
if(LOG_LEVEL <= DEBUG) *debug_stream << "Afraid Dark module initialised!" << endl;
return true;
}
void ClydeAfraidDark::update() {
getLight();
}
uint16_t ClydeAfraidDark::getLight() {
light = analogRead(apin);
return light;
}