/usr/lib/cgi-bin/pythonHW/index.cgi

[Ritorna]

#!/usr/bin/python # # Copyright (C) 2016 Ing. Stefano Salvi<stefano@salvi.mn.it> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. import RPi.GPIO as GPIO import cgi import cgitb import time cgitb.enable() print "Content-Type: text/html;charset=utf-8" print "" print '<!DOCTYPE html>' print '<html lang="it">' print ' <head>' print ' <title>Raspberry-My Programmazione in Python con hardsware</title>' print ' <meta charset="utf-8">' print ' <meta name="author" content="Ing. Stefano Salvi">' print ' <link rel="stylesheet" type="text/css" href="../../css/index.css">' print ' <script type="text/javascript" src="../../js/index.js"></script>' print ' <script type="text/javascript" src="../../js/testled.js"></script>' print ' </head>' print ' <body onload="setInterval(testLed, 500)">' print ' <!-- Dialog -->' print ' <div id="isf_overlay">' print ' <div id="isf_overlay_frame">' print ' <div id="isf_overlay_content">' print ' <h2>' print ' Dialog modale visualizzato dal Javascript' print ' </h2><p>' print ' &Egrave; possibile fare comparire un dialog sopra la pagina, che scompaia con un bottone.' print ' </p>' print ' </div>' print ' <div id="isf_overlay_bottom">' print ' <input id="isf_overlay_close_button" type="button" onClick="closeDialog()" value="Chiudi">' print ' </div>' print ' </div>' print ' </div>' print ' <!-- Fine Dialog -->' print ' <!-- Slideshow -->' print ' <div id="testa-carousel">' print ' <div id="testa-slideshow">' print ' <img src="../../img/little_pi.png" alt="Raspberry Pi 3" width="400" height="400" />' print ' <img src="../../img/raspberry-pi-2-angle-100569133-orig.png" alt="Raspberry Pi 3" width="400" height="400" />' print ' <img src="../../img/Raspberry_Pi_-_Model_A.jpg" alt="Raspberry Pi Model A" width="400" height="400" />' print ' <img src="../../img/rpi1bplus.png" alt="Raspberry Pi 2" width="400" height="400" />' print ' </div>' print ' </div>' print ' <!-- Fine Slideshow -->' print " <script type=\"text/javascript\">var slides = new Slideshow('testa-slideshow', 1000, 400);</script>" print ' <h1>Esempi di programmazione in Python con hardsware</h1>' print ' <p>[<a href="../../index.html#pythonhw">Ritorna</a>]</p>' print ' <p><input type="button" onClick="openDialog()" value="Apri Dialog"></p>' print ' <form method="get" action="index.cgi">' print ' <p><input type="hidden" name="led" value="1">' print ' <input type="submit" value="Accendi LED"></p>' print ' </form>' print ' <form method="get" action="index.cgi">' print ' <p><input type="hidden" name="led" value="0">' print ' <input type="submit" value="Spegni LED"></p>' print ' </form>' print ' <form method="get" action="index.cgi">' print ' <p><input type="hidden" name="led" value="2">' print ' <input type="submit" value="CiaoCiao"></p>' print ' </form>' form = cgi.FieldStorage() GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(16, GPIO.OUT) GPIO.setup(6, GPIO.IN) GPIO.setup(18, GPIO.OUT) if "led" in form: if form["led"].value == '1': GPIO.output(16, GPIO.HIGH) elif form["led"].value == '0': GPIO.output(16, GPIO.LOW) else: p = GPIO.PWM(18, 100) # create an object p for PWM on port 25 at 50 Hertz p.start(6) # start the PWM on 50 percent duty cycle time.sleep(1) for x in range(25, 90): time.sleep(0.10) p.ChangeDutyCycle(x/4.0) for x in range(90, 25, -1): time.sleep(0.10) p.ChangeDutyCycle(x/4.0) p.stop() # stop the PWM output if GPIO.input(6) == 1: print ' <div id="showbutton" class="off">' else: print ' <div id="showbutton" class="on">' print ' </div>' print ' <div id="footer">' print ' <span class="author">Autore Stefano Salvi</span> <a href="mailto:stefano@salvi.mn.it" title="Indirizzo Mail di Salvi">stefano@salvi.mn.it</a>' print ' Rilasciato su licenza <a href="https://creativecommons.org/licenses/by-sa/3.0/it/legalcode" title="Attribuzione ../../img/cc_by_sa_88x31.png" alt="Logo Creative Commons" title="Logo Creative Commons"></a>' print ' </div>' print ' </body>' print '</html>'