From cf248664985b24cfc3c3302f657111cc571fbea4 Mon Sep 17 00:00:00 2001 From: Joerg Elfring Date: Sun, 1 Sep 2019 00:52:57 +0200 Subject: [PATCH] first commit --- README.md | 37 ++++++++ annunciatorServer/annunciatorServer.sh | 23 +++++ checkLedPins/checkLedPins.ino | 47 ++++++++++ led-annunciator/led-annunciator.ino | 119 +++++++++++++++++++++++++ led-annunciator/led_commands.ino | 29 ++++++ 5 files changed, 255 insertions(+) create mode 100644 README.md create mode 100755 annunciatorServer/annunciatorServer.sh create mode 100644 checkLedPins/checkLedPins.ino create mode 100644 led-annunciator/led-annunciator.ino create mode 100644 led-annunciator/led_commands.ino diff --git a/README.md b/README.md new file mode 100644 index 0000000..6388353 --- /dev/null +++ b/README.md @@ -0,0 +1,37 @@ +# LED Annunciator +A quick and dirty little device to inform people you are on the phone or in an +appointment with a traffic light. The state information are generated by a +groupware or messaging application that writes a single letter code into a file. + +| Command | Meaning | +|---------|---------------------------| +| a | Turn on all leds | +| 0 | Turn off all leds | +| r | Switch to the red line | +| g | Switch to the green line | +| y | Switch to the yellow line | + +AnnunciatorServer takes the code and sends it via serial port to the device. +Alternatively, similar commands can be send by an infrared remote control. + +## Hardware +An Arduino Nano with nine leds on pins D02 - D10. The leds are arranged in three +rows (red, yellow, green) of three leds each. +A YS1838B infrared receiver is connected to D11 and sits on top facing +backwards. + +## Software +### led-annunciator +The Arduino code. + +### checkLedPins +A program to check the led/pin mapping by turning them on one by one. + +### annunciatorServer +The shell script that checks a commandfile and sends single-character +commands to the serial port. +This is useful when the commandfile needs to sit on a network share. + +## Room for improvements +- Sometimes the ir receiver starts to send random codes +- As all leds are connected individually, many more commands can be defined. diff --git a/annunciatorServer/annunciatorServer.sh b/annunciatorServer/annunciatorServer.sh new file mode 100755 index 0000000..807cbfd --- /dev/null +++ b/annunciatorServer/annunciatorServer.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +port=/dev/ttyUSB0 +cmdfile=~/annunciatorServer.txt + +## Setup serial port +stty -F $port ispeed 9600 ospeed 9600 -ignpar cs8 -cstopb -hupcl + +## Setup files +touch $cmdfile + +## Monitor file for new commands +while true +do + incmd=$(head -c 1 $cmdfile) + if [ _$incmd != _ ] + then + echo $incmd > $port + > $cmdfile + fi + sleep 1 +done + diff --git a/checkLedPins/checkLedPins.ino b/checkLedPins/checkLedPins.ino new file mode 100644 index 0000000..753973f --- /dev/null +++ b/checkLedPins/checkLedPins.ino @@ -0,0 +1,47 @@ +// Pins +int r1 = 5; // Rot 1 an Pin 5 +int r2 = 6; // Rot 2 an Pin 6 +int r3 = 4; // Rot 3 an Pin 4 +int y1 = 7; // Gelb 1 an Pin 7 +int y2 = 9; // Gelb 2 an Pin 9 +int y3 = 8; // Gelb 3 an Pin 8 +int g1 = 2; // Grün 1 an Pin 2 +int g2 = 10; // Grün 2 an Pin 10 +int g3 = 3; // Grün 3 an Pin 3 +int ir = 11; // IR Empfänger an Pin 11 + +void setup() { + pinMode(r1, OUTPUT); + pinMode(r2, OUTPUT); + pinMode(r3, OUTPUT); + pinMode(y1, OUTPUT); + pinMode(y2, OUTPUT); + pinMode(y3, OUTPUT); + pinMode(g1, OUTPUT); + pinMode(g2, OUTPUT); + pinMode(g3, OUTPUT); +} + +void loop() { + for (int i = 2; i <= 10; i++) { + digitalWrite(i, LOW); + } + digitalWrite(r1, HIGH); + delay(1000); + digitalWrite(r2, HIGH); + delay(1000); + digitalWrite(r3, HIGH); + delay(1000); + digitalWrite(y1, HIGH); + delay(1000); + digitalWrite(y2, HIGH); + delay(1000); + digitalWrite(y3, HIGH); + delay(1000); + digitalWrite(g1, HIGH); + delay(1000); + digitalWrite(g2, HIGH); + delay(1000); + digitalWrite(g3, HIGH); + delay(5000); +} diff --git a/led-annunciator/led-annunciator.ino b/led-annunciator/led-annunciator.ino new file mode 100644 index 0000000..89e8f2b --- /dev/null +++ b/led-annunciator/led-annunciator.ino @@ -0,0 +1,119 @@ + + +// Pins +int r1 = 5; // Rot 1 an Pin 5 +int r2 = 6; // Rot 2 an Pin 6 +int r3 = 4; // Rot 3 an Pin 4 +int y1 = 7; // Gelb 1 an Pin 7 +int y2 = 9; // Gelb 2 an Pin 9 +int y3 = 8; // Gelb 3 an Pin 8 +int g1 = 2; // Grün 1 an Pin 2 +int g2 = 10; // Grün 2 an Pin 10 +int g3 = 3; // Grün 3 an Pin 3 +int ir = 11; // IR receiver an Pin 11 + +// Prepare ir device +#include +IRrecv irrecv(ir); +decode_results results; + +void setup() { + // LED Pins + pinMode(r1, OUTPUT); + pinMode(r2, OUTPUT); + pinMode(r3, OUTPUT); + pinMode(y1, OUTPUT); + pinMode(y2, OUTPUT); + pinMode(y3, OUTPUT); + pinMode(g1, OUTPUT); + pinMode(g2, OUTPUT); + pinMode(g3, OUTPUT); + pinMode(ir, INPUT); + + // IR Receiver + irrecv.enableIRIn(); // Activate IR Pin + + // Serielle Schnittstelle + Serial.begin(9600); +} + + +void loop() { + + // SERIAL + while (Serial.available()) { + String rcv_sr = Serial.readString(); + + // Send data to serial port + Serial.println("RX serial: " + rcv_sr); + + // Switch LEDs + switch (rcv_sr[0]) { + case 'g' : + led_allOff(); + led_greenLine(); + break; + + case 'a' : + led_greenLine(); + led_redLine(); + led_yllwLine(); + break; + + case 'y' : + led_allOff(); + led_yllwLine(); + break; + + case 'r' : + led_allOff(); + led_redLine(); + break; + + case '0' : + led_allOff(); + break; + } + + } + + // IR + if (irrecv.decode(&results)) { + int rcv_ir = results.value; + + // Send data to serial port + Serial.println("RX ir: " + String(rcv_ir)); + + // Switch LEDs + switch (rcv_ir) { + case -23971 : //Taste 1 + led_allOff(); + led_greenLine(); + break; + + case 25245 : //Taste 2 + led_allOff(); + led_yllwLine(); + break; + + case -7651 : //Taste 2 + led_allOff(); + led_redLine(); + break; + + case 26775 : //Taste 0 + led_allOff(); + break; + + case -26521 : //Taste +100 + led_greenLine(); + led_redLine(); + led_yllwLine(); + break; + + } + + // ReArm IR + irrecv.resume(); + } +} diff --git a/led-annunciator/led_commands.ino b/led-annunciator/led_commands.ino new file mode 100644 index 0000000..1df88ea --- /dev/null +++ b/led-annunciator/led_commands.ino @@ -0,0 +1,29 @@ +void led_allOff() { + digitalWrite (r1, LOW); + digitalWrite (r2, LOW); + digitalWrite (r3, LOW); + digitalWrite (g1, LOW); + digitalWrite (g2, LOW); + digitalWrite (g3, LOW); + digitalWrite (y1, LOW); + digitalWrite (y2, LOW); + digitalWrite (y3, LOW); +} + +void led_redLine() { + digitalWrite (r1, HIGH); + digitalWrite (r2, HIGH); + digitalWrite (r3, HIGH); +} + +void led_yllwLine() { + digitalWrite (y1, HIGH); + digitalWrite (y2, HIGH); + digitalWrite (y3, HIGH); +} + +void led_greenLine() { + digitalWrite (g1, HIGH); + digitalWrite (g2, HIGH); + digitalWrite (g3, HIGH); +}