]> Johnzone git - FakeRadio.git/commitdiff
initial commit, LEDs and Buttons are working
authorJohn Janus <mail@johnzone.org>
Sun, 27 Aug 2017 07:45:31 +0000 (09:45 +0200)
committerJohn Janus <mail@johnzone.org>
Sun, 27 Aug 2017 07:45:31 +0000 (09:45 +0200)
simple_try.c [new file with mode: 0644]

diff --git a/simple_try.c b/simple_try.c
new file mode 100644 (file)
index 0000000..9c8df92
--- /dev/null
@@ -0,0 +1,86 @@
+#include <wiringPi.h>
+#include <stdio.h>
+#include <stdbool.h>
+#include <signal.h>
+
+#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);
+}
+