46 lines
733 B
C++
46 lines
733 B
C++
#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;
|
|
}
|
|
}
|