changed from a normal RGB led to neopixel ws2812b

py3
Gunstick 2015-05-02 01:58:10 +02:00
parent 06f1e1ae6a
commit d2c4ef06a6
4 changed files with 114 additions and 70 deletions

View File

@ -4,15 +4,21 @@ the button has an RGB led to show status
how to install
==============
# login as user pi
sudo apt-get install unclutter xdotool git-core screen imagemagick
cd ~
git clone https://github.com/syn2cat/doorbuzz.git
put into /etc/rc.local the following line:
su pi -c '/home/pi/buzzctrl.sh' &
su pi -c '/home/pi/doorbuzz/buzzctrl.sh' &
sudo vi /etc/xdg/lxsession/LXDE/autostart
remove screensaver
sudo apt-get install unclutter xdotool git-core screen imagemagick
cd ~
git clone git://git.drogon.net/wiringPi
cd wiringPi
./build
cd ~
mkdir -p /home/pi/.config/lxsession/LXDE/
cat > /home/pi/.config/lxsession/LXDE/autostart <<"EOF"
@ -20,9 +26,18 @@ cat > /home/pi/.config/lxsession/LXDE/autostart <<"EOF"
@xset -dpms
@xset s noblank
@unclutter -display :0 -noevents -grab
@./videoplayer.sh
@./doorbuzz/videoplayer.sh
EOF
https://learn.adafruit.com/neopixels-on-raspberry-pi/software
sudo apt-get install build-essential python-dev git scons swig
git clone https://github.com/jgarff/rpi_ws281x.git
cd rpi_ws281x
scons
cd python
sudo python setup.py install
cd doorbuzz
connect the button and LED to pins as shown in buzzctrl.sh
create a file "secret.txt" containing the http://user:pass@10.1.1.xx part of the URL

View File

@ -1,57 +1,38 @@
#!/bin/bash
# led is not neopixel, so use the python lib for that
BUTTONPIN=25
REDLEDPIN=23
GREENLEDPIN=18
BLUELEDPIN=24
SHOWLEDPRG="sudo python /home/pi/doorbuzz/setneocolor.py"
BUZZERURL="$(cat "$(dirname "$0")"/secret.txt)/state.xml?relay1State=2&pulseTime1=5"
BUZZERSTATUSURL="$(cat "$(dirname "$0")"/secret.txt)/state.xml"
ATTENUATION=4
# file secret.txt should contain username:password
# install by putting into /etc/rc.local
# su pi -c '/home/pi/buzzctrl.sh' &
# su pi -c '/home/pi/doorbuzz/buzzctrl.sh' &
echo "Initializing hardware"
# the button
gpio -g mode $BUTTONPIN up
gpio -g mode $BUTTONPIN in
# R
gpio -g mode $REDLEDPIN out
# G
gpio -g mode $GREENLEDPIN out
# B
gpio -g mode $BLUELEDPIN out
pulseon() {
pin=$1
value=0
valueinc=64
gpio -g mode $pin pwm
while true
do
gpio -g pwm $pin $value
value=$((value+valueinc))
if [ $value -gt 1023 ] || [ $value -lt 0 ]
then
valueinc=$((0-valueinc))
value=$((value+valueinc))
fi
sleep 0.2
done
red=$1
green=$2
blue=$3
$SHOWLEDPRG pulse $((red/ATTENUATION)) $((green/ATTENUATION)) $((blue/ATTENUATION)) </dev/null >/dev/null 2>&1 &
echo $!
}
pulseoff() {
pin=$1
kill $2
gpio -g mode $pin out
gpio -g write $pin 0
if [ $(ps -edf | grep pulse | grep "$1"|wc -l) -gt 0 ]
then
sudo kill "$1"
fi
}
ledcolor() {
red=$1
green=$2
blue=$3
gpio -g write $REDLEDPIN $red
gpio -g write $GREENLEDPIN $green
gpio -g write $BLUELEDPIN $blue
$SHOWLEDPRG set $((red/ATTENUATION)) $((green/ATTENUATION)) $((blue/ATTENUATION))
}
declare -a morse
morse[0]="-----"
@ -69,68 +50,54 @@ morseled() {
echo $message
msglen=${#message}
pos=0
morsecode=""
while [ $pos -lt $msglen ]
do
morsecode=${morse[${message:${pos}:1}]}
morsecode="$morsecode ${morse[${message:${pos}:1}]}"
pos=$((pos+1))
echo $morsecode
morselen=${#morsecode}
morsepos=0
while [ $morsepos -lt $morselen ]
do
ledcolor $2 $3 $4
#echo "c($morsepos)=${morsecode:${morsepos}:1}"
if [ "${morsecode:${morsepos}:1}" = "." ]
then
#echo "."
sleep 0.1
else
#echo "-"
sleep 0.2
fi
ledcolor 0 0 0
sleep 0.1
morsepos=$((morsepos+1))
done
sleep 0.2
echo
done
red=$2
green=$3
blue=$4
$SHOWLEDPRG morse $((red/ATTENUATION)) $((green/ATTENUATION)) $((blue/ATTENUATION)) "$morsecode"
echo
}
echo "morsing IP"
ledcolor 1 1 1
ledcolor 255 255 255
sleep 3
ledcolor 0 0 0
sleep 1
morseled "$(hostname -I|awk -F. '{sub(" ","",$NF);printf $NF}')" 1 0 0
ledcolor 1 1 1
morseled "$(hostname -I|awk -F. '{sub(" ","",$NF);printf $NF}')" 255 0 0
ledcolor 255 255 255
sleep 1
echo "Main loop"
while true
do
ledcolor 0 1 1
pulseon $GREENLEDPIN &
pulsepid=$!
trap "pulseoff $GREENLEDPIN $pulsepid;ledcolor 0 0 0;exit" 1 2 3
ledcolor 0 255 255
pulsepid=$(pulseon 0 0 255 )
trap "pulseoff $pulsepid;ledcolor 0 0 0;exit" 1 2 3
gpio -g wfi $BUTTONPIN falling
while [ $(gpio -g read $BUTTONPIN) != 0 ]
do
gpio -g wfi $BUTTONPIN falling
done
pulseoff $GREENLEDPIN $pulsepid
ledcolor 0 1 1
pulseoff $pulsepid
ledcolor 0 255 255
echo "Pushiii"
wget -O - -S --timeout=1 --tries=1 "$BUZZERURL" 2>&1
ret=$?
if [ $ret -ne 0 ]
then
morseled "$ret" 1 0 0
morseled "$ret" 255 0 0
else
while wget -O - --timeout=1 --tries=1 $BUZZERSTATUSURL|grep '<relay1state>1</relay1state>'
do
ledcolor 0 1 0
ledcolor 0 255 0
sleep 0.9
ledcolor 0 1 1
ledcolor 0 255 255
sleep 0.1
done
fi

62
setneocolor.py Executable file
View File

@ -0,0 +1,62 @@
#!/usr/bin/python
# sets color of first neo pixel
from __future__ import division
import time
import sys
from math import *
from neopixel import *
# LED strip configuration:
LED_COUNT = 1 # Number of LED pixels.
LED_PIN = 18 # GPIO pin connected to the pixels (must support PWM!).
LED_FREQ_HZ = 800000 # LED signal frequency in hertz (usually 800khz)
LED_DMA = 5 # DMA channel to use for generating signal (try 5)
LED_BRIGHTNESS = 100 # Set to 0 for darkest and 255 for brightest
LED_INVERT = False # True to invert the signal (when using NPN transistor level shift)
# Main program logic follows:
if __name__ == '__main__':
# Create NeoPixel object with appropriate configuration.
strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS)
# Intialize the library (must be called once before other functions).
strip.begin()
r=int(sys.argv[2])
g=int(sys.argv[3])
b=int(sys.argv[4])
if(sys.argv[1] == "set"):
print "Color set to: ",r,g,b
strip.setPixelColor(0, Color(r,g,b))
strip.show()
if(sys.argv[1] == "morse"):
print "Morsing with: ",r,g,b
speed=10
morsecode=sys.argv[5]
for c in morsecode:
if c==".":
strip.setPixelColor(0, Color(r,g,b))
strip.show()
time.sleep(0.2)
strip.setPixelColor(0, Color(0,0,0))
strip.show()
time.sleep(0.2)
if c=="-":
strip.setPixelColor(0, Color(r,g,b))
strip.show()
time.sleep(0.7)
strip.setPixelColor(0, Color(0,0,0))
strip.show()
time.sleep(0.2)
if c==" ":
strip.setPixelColor(0, Color(0,0,0))
strip.show()
time.sleep(1)
if(sys.argv[1] == "pulse"):
print "Pulsing with: ",r,g,b
pulsewidth=50
while True:
for i in range(pulsewidth):
trigo=sin(i/pulsewidth*pi)
strip.setPixelColor(0, Color(int(r*trigo),int(g*trigo),int(b*trigo)))
strip.show()
time.sleep(50/1000.0)

View File

@ -13,7 +13,7 @@ do
then # test on false, so in case of network fail, it defaults to playing
sleep 60
else
ls *mp4 |
ls ~/*mp4 |
while read video
do
omxplayer "$video" </dev/null