From a5d4cfb5e28c6cf8b03fbbe53132565bbac71968 Mon Sep 17 00:00:00 2001 From: Gunstick Date: Fri, 8 May 2015 21:27:28 +0200 Subject: [PATCH] added button to clean shutdown the pi added the adafruit 60 neopixel display code to show the actual time as analog clock --- README.txt | 21 +++------------------ setneocolor.py | 17 +++++++++++++++-- shutdownbutton.py | 18 ++++++++++++++++++ videoplayer.sh | 1 + 4 files changed, 37 insertions(+), 20 deletions(-) create mode 100644 shutdownbutton.py diff --git a/README.txt b/README.txt index b437c7e..de1718b 100644 --- a/README.txt +++ b/README.txt @@ -4,21 +4,13 @@ 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/doorbuzz/buzzctrl.sh' & sudo vi /etc/xdg/lxsession/LXDE/autostart remove screensaver -cd ~ +sudo apt-get install unclutter xdotool git-core screen imagemagick 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" @@ -26,18 +18,11 @@ cat > /home/pi/.config/lxsession/LXDE/autostart <<"EOF" @xset -dpms @xset s noblank @unclutter -display :0 -noevents -grab +@./doorbuzz/buzzctrl.sh @./doorbuzz/videoplayer.sh +@sudo python ./doorbuzz/shutdownbutton.py 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 diff --git a/setneocolor.py b/setneocolor.py index 5b68c4c..7958060 100755 --- a/setneocolor.py +++ b/setneocolor.py @@ -8,13 +8,16 @@ from math import * from neopixel import * # LED strip configuration: -LED_COUNT = 1 # Number of LED pixels. +LED_COUNT = 61 # 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) +def clockcalc(value): + return 1+((30+int(value))%60) + # Main program logic follows: if __name__ == '__main__': # Create NeoPixel object with appropriate configuration. @@ -56,7 +59,17 @@ if __name__ == '__main__': pulsewidth=50 while True: for i in range(pulsewidth): + color=Color(0,0,0) + for j in range(0,60): + strip.setPixelColor(clockcalc(j), color) trigo=sin(i/pulsewidth*pi) - strip.setPixelColor(0, Color(int(r*trigo),int(g*trigo),int(b*trigo))) + color=Color(int(r*trigo),int(g*trigo),int(b*trigo)) + clockpos=int(time.strftime('%I',time.localtime()))*5 + for j in range(-2,3): + strip.setPixelColor(clockcalc(clockpos+j),Color(30,30,30)) + for j in range(0,60,5): + strip.setPixelColor(clockcalc(j), color) + strip.setPixelColor(clockcalc(time.strftime('%M',time.localtime())),Color(30,0,0)) + strip.setPixelColor(clockcalc(time.strftime('%S',time.localtime())),Color(0,30,0)) strip.show() time.sleep(50/1000.0) diff --git a/shutdownbutton.py b/shutdownbutton.py new file mode 100644 index 0000000..b70ebb7 --- /dev/null +++ b/shutdownbutton.py @@ -0,0 +1,18 @@ +buttonpin=24 +import RPi.GPIO as GPIO +import time +import os + +GPIO.setmode(GPIO.BCM) + +GPIO.setup(buttonpin, GPIO.IN, pull_up_down=GPIO.PUD_UP) + +while True: + print "waiting..." + try: + GPIO.wait_for_edge(buttonpin, GPIO.FALLING) + print('Button Pressed') + os.system("shutdown now -h") + except KeyboardInterrupt: + GPIO.cleanup() # clean up GPIO on CTRL+C exit +GPIO.cleanup() # diff --git a/videoplayer.sh b/videoplayer.sh index 7cff5ec..c41c0a9 100755 --- a/videoplayer.sh +++ b/videoplayer.sh @@ -17,6 +17,7 @@ do while read video do omxplayer "$video"