forked from adamgreen/MiP_ProMini-Pack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChestLED.ino
More file actions
163 lines (148 loc) · 5.13 KB
/
Copy pathChestLED.ino
File metadata and controls
163 lines (148 loc) · 5.13 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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/**
* @file ChestLED.ino
* @brief Example sketch demonstrating MiP chest LED read and write operations.
*
* @details This sketch shows how to set and read MiP's chest LED color and
* blink timing. It demonstrates verified write APIs (chestLED.read() and
* chestLED.write()) and unverified fire-and-forget write APIs
* (chestLED.unverifiedWrite()), which send commands without read-back checks.
*
* The example exercises these API calls:
* - chestLED.read()
* - chestLED.write()
* - chestLED.unverifiedWrite()
*
* @author Adam Green (Original Author)
* @author Samuel Trassare (Maintainer)
* @copyright Copyright (C) 2018-2026 Samuel Trassare
* (https://github.com/Tiogaplanet) Licensed under the Apache License,
* Version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*/
#include <MiP_Power_Up_-_Pro_Mini.h>
/**
* @brief Global MiP instance used to communicate with MiP.
*
* This object is used throughout the sketch to call MiP API functions such as
* begin(), chestLED.read(), chestLED.write(), and chestLED.unverifiedWrite().
*/
MiP mip;
/**
* @brief Stores the result of the MiP initialization attempt.
*/
bool connectResult;
/**
* @brief Prints the current chest LED setting to mip.console.
*
* @details Reads the current chest LED state from MiP using chestLED.read()
* and prints the red, green, blue, onTime, and offTime values in a
* human-readable format.
*/
static void printCurrentChestLEDSetting() {
MiPChestLED chestLED;
mip.chestLED.read(chestLED);
mip.console.println(F(" Current Chest LED Setting"));
mip.console.print(F(" red: "));
mip.console.println(chestLED.red);
mip.console.print(F(" green: "));
mip.console.println(chestLED.green);
mip.console.print(F(" blue: "));
mip.console.println(chestLED.blue);
mip.console.print(F(" on time: "));
mip.console.print(chestLED.onTime);
mip.console.println(F(" milliseconds"));
mip.console.print(F(" off time: "));
mip.console.print(chestLED.offTime);
mip.console.println(F(" milliseconds"));
}
/**
* @brief Arduino setup function.
*
* @details Initializes communication with MiP and demonstrates several
* chest LED operations:
* - Setting a static color (magenta) with no flash timing specified.
* - Setting a blinking color (red) with explicit on/off times.
* - Setting a static color (green) using a MiPChestLED struct.
* - Repeating the sequence using unverified write APIs.
*
* The function prints status messages to mip.console and uses
* printCurrentChestLEDSetting() to display the current chest LED state after
* each verified write.
*/
void setup() {
connectResult = mip.begin();
if (!connectResult) {
Serial.println(F("ChestLED.ino: Failed connecting to MiP!"));
return;
}
mip.console.println(F("ChestLED.ino: Set Chest LED to different colors."));
// 1. Set static color (magenta) using verified write
mip.console.println(F(" Set chest LED to magenta, no time specified."));
uint8_t red = 0xFF;
uint8_t green = 0x01;
uint8_t blue = 0xFE;
mip.chestLED.write(red, green, blue);
printCurrentChestLEDSetting();
delay(1000);
// 2. Set flashing color (red) using verified write
mip.console.println(F(" Set chest LED to blink red, on time: 990ms, off time: 989ms."));
red = 0xFF;
green = 0x01;
blue = 0x05;
const uint16_t onTime = 990;
const uint16_t offTime = 989;
mip.chestLED.write(red, green, blue, onTime, offTime);
printCurrentChestLEDSetting();
delay(4000);
// 3. Set static color (green) using a MiPChestLED struct
mip.console.println(F(" Set chest LED back to green, no time specified."));
MiPChestLED chestLED;
chestLED.red = 0x00;
chestLED.green = 0xFF;
chestLED.blue = 0x00;
chestLED.onTime = 0;
chestLED.offTime = 0;
mip.chestLED.write(chestLED);
printCurrentChestLEDSetting();
delay(1000);
// 4. Repeat sequence using unverified write (fire-and-forget) APIs
mip.console.println(F(" Trying to set chest LED to magenta, no time specified."));
red = 0xFF;
green = 0x01;
blue = 0xFE;
mip.chestLED.unverifiedWrite(red, green, blue);
delay(1000);
mip.console.println(F(" Trying to set chest LED to blink red, with time specified."));
red = 0xFF;
green = 0x01;
blue = 0x05;
mip.chestLED.unverifiedWrite(red, green, blue, onTime, offTime);
delay(4000);
mip.console.println(F(" Trying to set chest LED back to green with a flash time."));
chestLED.red = 0x00;
chestLED.green = 0xFF;
chestLED.blue = 0x00;
chestLED.onTime = 200;
chestLED.offTime = 200;
mip.chestLED.unverifiedWrite(chestLED);
delay(1000);
// Restore solid green state at the end of the test
mip.console.println(F(" Set chest LED back to solid green."));
chestLED.red = 0x00;
chestLED.green = 0xFF;
chestLED.blue = 0x00;
chestLED.onTime = 0;
chestLED.offTime = 0;
mip.chestLED.write(chestLED);
mip.console.println(F("ChestLED.ino: Done."));
}
/**
* @brief Arduino loop function.
*
* This example performs all actions in setup() and does not require repeated
* work in loop().
*/
void loop() {
if (!connectResult) { return; }
}