-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboard_5110_proxi9930.ino
129 lines (108 loc) · 3.29 KB
/
board_5110_proxi9930.ino
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// LCD5110_NumberFonts
// Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved
// web: http://www.RinkyDinkElectronics.com/
//
// This program is a demo of the included number-fonts,
// and how to use them.
//
// This program requires a Nokia 5110 LCD module
// and Arduino 1.5.2 (or higher).
//
// It is assumed that the LCD module is connected to
// the following pins.
// SCK - Pin 8 >> 4
// MOSI - Pin 9 >> 5
// DC - Pin 10 >> 6
// RST - Pin 11 >> 8
// CS - Pin 12 >> 7
//
#define PIN_PLUS 3
#define PIN_BL 2
#include <LCD5110_Basic.h>
#include <Wire.h>
#include <APDS9930.h>
APDS9930 apds = APDS9930();
uint16_t proximity_data = 0;
float ambient_light = 0; // can also be an unsigned long
uint16_t ch0 = 0;
uint16_t ch1 = 1;
LCD5110 myGLCD(4,5,6,8,7);
extern uint8_t SmallFont[];
extern uint8_t MediumNumbers[];
extern uint8_t BigNumbers[];
int invertLCD=0;
void setup()
{
pinMode(PIN_PLUS, OUTPUT); // sets the digital pin as output
pinMode(PIN_BL, OUTPUT);
digitalWrite(PIN_PLUS, HIGH);
digitalWrite(PIN_BL, LOW);
myGLCD.InitLCD();
myGLCD.setContrast(60);
Serial.begin(9600);
Wire.begin();
Serial.println(F("---------------------------"));
Serial.println(F("APDS-9930 - ProximitySensor"));
Serial.println(F("---------------------------"));
// Initialize APDS-9930 (configure I2C and initial values)
if ( apds.init() ) {
Serial.println(F("APDS-9930 initialization complete"));
} else {
Serial.println(F("Something went wrong during APDS-9930 init!"));
}
// // Adjust the Proximity sensor gain
// if ( !apds.setProximityGain(PGAIN_2X) ) {
// Serial.println(F("Something went wrong trying to set PGAIN"));
// }
}
void loop()
{
char status;
myGLCD.clrScr();
invertLCD++;
// Start running the APDS-9930 proximity sensor (no interrupts)
if ( apds.enableProximitySensor(false) ) {
Serial.println(F("Proximity sensor is now running"));
} else {
Serial.println(F("Something went wrong during sensor init!"));
}
delay(200);
// Read the proximity value
if ( !apds.readProximity(proximity_data) ) {
Serial.println("Error reading proximity value");
} else {
Serial.print("Proximity: ");
Serial.println(proximity_data);
}
delay(200);
if ( apds.enableLightSensor(false) ) {
Serial.println(F("Light sensor is now running"));
} else {
Serial.println(F("Something went wrong during light sensor init!"));
}
// Read the light levels (ambient, red, green, blue)
if ( !apds.readAmbientLightLux(ambient_light) ||
!apds.readCh0Light(ch0) ||
!apds.readCh1Light(ch1) ) {
Serial.println(F("Error reading light values"));
} else {
Serial.print(F("Ambient: "));
Serial.print(ambient_light);
Serial.print(F(" Ch0: "));
Serial.print(ch0);
Serial.print(F(" Ch1: "));
Serial.println(ch1);
}
// myGLCD.setFont(MediumNumbers);
// myGLCD.print("BMP180",RIGHT, 0);
myGLCD.setFont(SmallFont);
myGLCD.print("Proxi",LEFT, 0);
myGLCD.setFont(MediumNumbers);
myGLCD.printNumI(proximity_data, RIGHT, 0);
myGLCD.setFont(SmallFont);
myGLCD.print("Lux",LEFT, 42);
myGLCD.setFont(BigNumbers);
myGLCD.printNumF(ambient_light,0, RIGHT, 24);
myGLCD.invert(invertLCD % 2);
delay(500);
}