From: John Janus Date: Sun, 27 Aug 2017 07:45:31 +0000 (+0200) Subject: initial commit, LEDs and Buttons are working X-Git-Url: https://git.johnzone.org/?a=commitdiff_plain;h=d9a4bea184ac3782efcb89c92a25a7491b380b0f;p=FakeRadio.git initial commit, LEDs and Buttons are working --- d9a4bea184ac3782efcb89c92a25a7491b380b0f 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); +} +