-
Notifications
You must be signed in to change notification settings - Fork 0
/
led_ct.c
104 lines (82 loc) · 2.52 KB
/
led_ct.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
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
// Program to test the virtual functioning of a group of LED in a system.
#include<stdint.h> // For the uint datatypes
#include<stdio.h> // For standard I/O
#define ON 1 // LED state ON
#define OFF 0 // LED satate OFF
#define INVALID_RGB_COLOR_FORMAT -1
#define LED_COUNT 3
// Stucture to store the settings parameters of the LED
struct LEDSettings {
uint8_t state;
uint8_t brightness;
uint32_t color;
};
// Structure to hold the individual as well as the group settings of the LED
struct LEDGroup {
struct LEDSettings singleLED;
uint8_t groupState;
uint8_t groupBrightness;
};
// Displays the statuses of the LEDs
int displayLEDGroupStatus(struct LEDGroup* group) {
int i = 0;
for(i=0;i< LED_COUNT; i++) {
printf("\nLED STATUS");
printf("\nIndividual LED > state: %d", group[i].singleLED.state);
printf("\nIndividual LED > brightness: %d", group[i].singleLED.brightness);
printf("\nIndividual LED > color: %d", group[i].singleLED.color);
printf("\nLED Group > state: %d", group[i].groupState);
printf("\nLED Group > brightness: %d\n", group[i].groupBrightness);
}
}
// Updtates the LED settings of the individual LEDs and the group
int updateLEDGroupSettings(
struct LEDGroup* group,
uint8_t groupState,
uint8_t groupBrightness,
uint8_t state,
uint8_t brightness,
uint32_t color
) {
int i = 0;
// Check if the RGB format is correct
if(color > 255255255) {
return INVALID_RGB_COLOR_FORMAT;
}
for(i=0;i< LED_COUNT; i++) {
group[i].singleLED.state = state;
group[i].singleLED.brightness = brightness;
group[i].singleLED.color = color;
group[i].groupState = groupState;
group[i].groupBrightness = groupBrightness;
}
return 0;
}
// Initializes the settings of individual LEDs and the group the are in.
int initLEDGroup(struct LEDGroup* group) {
// call the updateLEDGroupSettings with the default initial parameters
return updateLEDGroupSettings(
group,
OFF,
0,
OFF,
0,
0
);
}
// Entry point for the program
int main(void) {
// Declare an array of LEDs which forms a group.
struct LEDGroup boardLED[LED_COUNT];
// Initializes all the LEDs
initLEDGroup(boardLED);
updateLEDGroupSettings(
boardLED,
ON,
128,
ON,
128,
255000000
);
displayLEDGroupStatus(boardLED);
}