1
0
Fork 0

first commit

This commit is contained in:
Joerg Elfring 2019-09-01 00:52:57 +02:00
commit cf24866498
5 changed files with 255 additions and 0 deletions

37
README.md Normal file
View file

@ -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.

View file

@ -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

View file

@ -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);
}

View file

@ -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 <IRremote.h>
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();
}
}

View file

@ -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);
}