Skip to content

Commit bd21834

Browse files
fontamiHwfbraghiroli
authored andcommitted
Added RGB LED & Button initialization and useful user function
1 parent c52a3f8 commit bd21834

File tree

3 files changed

+83
-1
lines changed

3 files changed

+83
-1
lines changed

hardware/AMEL/samd/variants/AMEL_SmartEverything/variant.cpp

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1818
*/
1919

20-
#include "variant.h"
20+
#include <Arduino.h>
2121

2222
/*
2323
* Pins descriptions
@@ -271,3 +271,43 @@ void SERCOM5_Handler()
271271
{
272272
BLE.IrqHandler();
273273
}
274+
275+
276+
void LED_GREEN_ON(uint32_t value) {
277+
if (value == HIGH) {
278+
digitalWrite(PIN_LED_GREEN, LOW);
279+
} else if (value == LOW) {
280+
digitalWrite(PIN_LED_GREEN, HIGH);
281+
} else {
282+
digitalWrite(PIN_LED_GREEN, 255-value); // in case of PWM
283+
}
284+
}
285+
286+
void LED_RED_ON(uint32_t value) {
287+
if (value == HIGH) {
288+
digitalWrite(PIN_LED_RED, LOW);
289+
} else if (value == LOW) {
290+
digitalWrite(PIN_LED_RED, HIGH);
291+
} else {
292+
digitalWrite(PIN_LED_RED, 255-value); // in case of PWM
293+
}
294+
}
295+
296+
void LED_BLUE_ON(uint32_t value) {
297+
if (value == HIGH) {
298+
digitalWrite(PIN_LED_BLUE, LOW);
299+
} else if (value == LOW) {
300+
digitalWrite(PIN_LED_BLUE, HIGH);
301+
} else {
302+
digitalWrite(PIN_LED_BLUE, 255-value); // in case of PWM
303+
}
304+
}
305+
306+
int button1IsPressed(void) {
307+
return !digitalRead(PIN_SME_BUTTON1);
308+
}
309+
310+
311+
int button2IsPressed(void) {
312+
return !digitalRead(PIN_SME_BUTTON2);
313+
}

hardware/AMEL/samd/variants/AMEL_SmartEverything/variant.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,30 @@ static const uint8_t SCK = PIN_SPI_SCK ;
177177
#define PIN_USB_DM (29ul)
178178
#define PIN_USB_DP (30ul)
179179

180+
/*
181+
RGB wrapper function
182+
These functions has been created for a more comfortable use
183+
because internally wrap the inversion of the HIGH, LOW meaning
184+
185+
Using these function it remain the same Arduino User Experience to light a led
186+
HIGH = Light ON
187+
LOW = Light OFF
188+
189+
*/
190+
void LED_GREEN_ON(uint32_t value);
191+
void LED_RED_ON(uint32_t value);
192+
void LED_BLUE_ON(uint32_t value);
193+
194+
195+
/*
196+
User Button wrapper function.
197+
198+
return:
199+
1 = button PRESSED
200+
0 = button RELEASED
201+
*/
202+
int button1IsPressed(void);
203+
int button2IsPressed(void);
180204

181205
#ifdef __cplusplus
182206
}
@@ -229,6 +253,11 @@ extern Uart SigFox;
229253
#define SERIAL_PORT_HARDWARE Serial1
230254
#define SERIAL_PORT_HARDWARE_OPEN Serial1
231255

256+
257+
#define LED_GREEN_INIT pinMode(PIN_LED_GREEN, OUTPUT)
258+
#define LED_RED_INIT pinMode(PIN_LED_RED, OUTPUT)
259+
#define LED_BLUE_INIT pinMode(PIN_LED_BLUE, OUTPUT)
260+
232261

233262
extern uint8_t smeInitError;
234263
#endif /* _VARIANT_AMEL_SMARTEVERYTHING_ */

hardware/AMEL/samd/variants/AMEL_SmartEverything/variantInit.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,19 @@ void initVariant() {
156156
delay(10); // just wait a while
157157
digitalWrite(PIN_IO_EXT_RST, HIGH);
158158

159+
// initialize button1 & button2 as input
160+
pinMode(PIN_SME_BUTTON1, INPUT_PULLUP);
161+
pinMode(PIN_SME_BUTTON2, INPUT_PULLUP);
162+
163+
164+
// initialize RGB LED
165+
LED_GREEN_INIT;
166+
LED_RED_INIT;
167+
LED_BLUE_INIT;
168+
LED_GREEN_ON(LOW);
169+
LED_BLUE_ON(LOW);
170+
LED_RED_ON(LOW);
171+
159172

160173
// initialize the IO_Extender
161174
ioExtenderInit();

0 commit comments

Comments
 (0)