From d9a4bea184ac3782efcb89c92a25a7491b380b0f Mon Sep 17 00:00:00 2001 From: John Janus Date: Sun, 27 Aug 2017 09:45:31 +0200 Subject: [PATCH 1/1] initial commit, LEDs and Buttons are working --- simple_try.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 simple_try.c diff --git a/simple_try.c b/simple_try.c new file mode 100644 index 0000000..9c8df92 --- /dev/null +++ b/simple_try.c @@ -0,0 +1,86 @@ +#include +#include +#include +#include + +#define PWRLED 8 +#define CHNL1LED 9 +#define CHNL2LED 7 + +#define PWRBTN 0 +#define CHNL1BTN 2 +#define CHNL2BTN 3 + +static volatile bool running = true; +static volatile bool pwrOn = false; +static volatile bool chnl1 = true; + +void ctrlCHandler(int dummy) { + running = false; + return; + +} + +void pwrBtn(void) { + pwrOn = !pwrOn; +} + +void chnl1Btn(void) { + chnl1 = true; +} + +void chnl2Btn(void) { + chnl1 = false; +} + +int main(void) { + if (wiringPiSetup() == -1) { + printf("Error during setup"); + return 1; + } + signal(SIGINT, ctrlCHandler); + wiringPiISR(PWRBTN, INT_EDGE_RISING, pwrBtn); + wiringPiISR(CHNL1BTN, INT_EDGE_RISING, chnl1Btn); + wiringPiISR(CHNL2BTN, INT_EDGE_RISING, chnl2Btn); + + pinMode(PWRLED, OUTPUT); + pinMode(CHNL1LED, OUTPUT); + pinMode(CHNL2LED, OUTPUT); + + /*pinMode(PWRBTN, INPUT); + pinMode(CHNL1BTN, INPUT); + pinMode(CHNL2BTN, INPUT); + pullUpDnControl(PWRBTN, PUD_UP); + pullUpDnControl(CHNL1BTN, PUD_UP); + pullUpDnControl(CHNL2BTN, PUD_UP);*/ + + while (running) { + /*digitalWrite(PWRLED, LOW); + digitalWrite(CHNL1LED, LOW); + digitalWrite(CHNL2LED, HIGH); + delay(5000); + digitalWrite(CHNL2LED, LOW); + digitalWrite(CHNL1LED, HIGH); + delay(5000);*/ + if (!pwrOn) { + digitalWrite(PWRLED, HIGH); + digitalWrite(CHNL1LED, HIGH); + digitalWrite(CHNL2LED, HIGH); + delay(500); + continue; + } + digitalWrite(PWRLED, LOW); + if (chnl1) { + digitalWrite(CHNL1LED, LOW); + digitalWrite(CHNL2LED, HIGH); + } else { + digitalWrite(CHNL2LED, LOW); + digitalWrite(CHNL1LED, HIGH); + } + + } + digitalWrite(PWRLED, HIGH); + digitalWrite(CHNL1LED, HIGH); + digitalWrite(CHNL2LED, HIGH); +} + -- 2.47.0