-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
48 lines (36 loc) · 1.23 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
#include <Wire.h>
#include <AK9723.h>
#include <AK9730.h>
// Define LED pin
const int LED_PIN = 13;
// Define Photodiode pin
const int PHOTODIODE_PIN = A0;
// Create instances of LED driver and Photodiode classes
AK9723 ledDriver;
AK9730 photodiode;
void setup() {
// Initialize LED pin as output
pinMode(LED_PIN, OUTPUT);
// Initialize I2C communication
Wire.begin();
// Set LED driver to power-down mode
ledDriver.setOperatingMode(PDN_MODE);
// Initialize LED driver
ledDriver.init();
// Initialize Photodiode
photodiode.init();
}
void loop() {
//Turn ON the LED for 4 seconds and Turn OFF the LED for another 4 seconds
digitalWrite(LED_PIN, HIGH); // Turn ON the LED
delay(4000); // Wait for 4 seconds
digitalWrite(LED_PIN, LOW); // Turn OFF the LED
delay(4000); // Wait for another 4 seconds
//Control the intensity of the LED wrt ambient light intensity
int ambientLight = photodiode.getAmbientLight(); // Read ambient light intensity
int ledIntensity = map(ambientLight, 0, 1023, 0, 255); // Map ambient light intensity to LED intensity
// Set LED intensity
ledDriver.setLEDIntensity(ledIntensity);
// Add some delay for stability
delay(1000);
}