Ajout librairie LED

This commit is contained in:
Paul Faure 2022-01-14 20:48:28 +01:00
parent 2547fbaaf1
commit 54d507ce52
6 changed files with 76 additions and 0 deletions

View file

View file

View file

16
gateway/gateway.ino Normal file
View file

@ -0,0 +1,16 @@
#include "led.h"
void setup() {
initLed(Green, 8);
initLed(Blue, 7);
initLed(Red, 6);
}
void loop() {
blinkLed(Red);
turnOnLed(Blue);
delay(1000);
turnOnLed(Green);
delay(1000);
turnOffLed(Blue);
}

46
gateway/led.cpp Normal file
View file

@ -0,0 +1,46 @@
#include "led.h"
#define LED_ON LOW
#define LED_OFF HIGH
int pins[] = {-1, -1, -1, -1, -1};
void initLed(color c, int pin) {
if (pins[c] == -1) {
pinMode(pin, OUTPUT);
}
pins[c] = pin;
digitalWrite(pin, LED_OFF);
}
int blinkLed(color c) {
if (pins[c] != -1) {
for (int i = 0; i<5; i++) {
digitalWrite(pins[c], LED_ON);
delay(50);
digitalWrite(pins[c], LED_OFF);
delay(50);
}
return 0;
} else {
return -1;
}
}
int turnOnLed(color c) {
if (pins[c] != -1) {
digitalWrite(pins[c], LED_ON);
return 0;
} else {
return -1;
}
}
int turnOffLed(color c) {
if (pins[c] != -1) {
digitalWrite(pins[c], LED_OFF);
return 0;
} else {
return -1;
}
}

14
gateway/led.h Normal file
View file

@ -0,0 +1,14 @@
#ifndef LED_H
#define LED_H
#include <Arduino.h>
enum color{Red, Blue, Green, White, Yellow};
void initLed(color c, int pin);
int blinkLed(color c);
int turnOnLed(color c);
int turnOffLed(color c);
#endif