示例#1
0
def init():
    #Temperature use Analog pin 1
    temperature.init()

    #LED use Digital pin 13
    led.init()

    #Light is on I2C, doesn't use a specific pin
    light.init()

    #Sound uses A0 Grove Port
    sound.init()

    #LCD is on I2C, doesn't use a specific pin
    lcd.init()
    lcd.setRGB(0,255,0)

    #Air Quality is on Analog Pin 1
    air_quality.init()
    
    #Led bar is on pin D8, uses pin 8 and 9
    led_bar.init()
示例#2
0
    def start(self):
        """ starts the whole program to run an led animation """
        # initialize buffers
        image.initialize_buffers()

        # start threads:
        self.calc_thread = image.PwmCalculation(debug=True)
        self.calc_thread.start()

        boards = led.init(find_all=True)
        self.board_threads = []
        for b in boards:
           print "found board", b
           t = image.Board(b)
           t.start()
           self.board_threads.append(t)

        # start synchronisation
        try:
            self.sync = syncboard.Syncboard('/dev/ttyUSB0', self.handle_serial_event)
            #self.sync.setVar('dip', '180') # remove later, just a debugging option
            # adc threshhold
            self.sync.setVar('adc', '200')
            self.sync.startReading()
        except serial.SerialException:
            print 'Sync board not found!'


        if self.init_server:
            # start server
            HOST, PORT = "localhost", 28900
            self.server = SocketServer.TCPServer((HOST, PORT), TcpServer.MyTCPHandler)
            self.server.serve_forever()

            # start server
            HOST, PORT = "localhost", 28900
            #self.server = SocketServer.TCPServer((HOST, PORT), TcpServer.MyTCPHandler)
            #self.server.serve_forever()
        else:
            # just show a debug picture
            fh = open('testbild.bin', 'rb')
            image.image_buffer[1] = fh.read()
            print 'testbild_size', len(image.image_buffer[1])
            image.image_current += 1
            while(1):
                time.sleep(1)
示例#3
0
print "Initializing pid controllers"
gx=pid.PID(pid_P_gyro,pid_I_gyro,pid_D_gyro)
gy=pid.PID(pid_P_gyro,pid_I_gyro,pid_D_gyro)
gz=pid.PID(pid_P_gyro,pid_I_gyro,pid_D_gyro)
ax=pid.PID(pid_P_gyro,pid_I_gyro,pid_D_gyro)
ay=pid.PID(pid_P_gyro,pid_I_gyro,pid_D_gyro)
az=pid.PID(pid_P_gyro,pid_I_gyro,pid_D_gyro)
gx.setPoint(gx_sp)
gy.setPoint(gy_sp)
gz.setPoint(gz_sp)
ax.setPoint(ax_sp)
ax.setPoint(ax_sp)
ax.setPoint(ax_sp)

print "Initializing LEDS"
led.init()
led.right("01")
led.left("01")
print "Initializing PWM"
pwm.init()
pwm=pwm.PWM()
time.sleep(1/3)
signal.signal(signal.SIGINT, signal_handler)
configuration_read()
print "Initializing menus"
init_menus()
menu.unbuffer_stdin()
welcome_menu.display()

while 1:
	main_menu.display()
示例#4
0
lastSend = 0
lastReadTemp = 0
lastReadCard = 0
tempReveil = 10
nbValeur = 87
intCard = 10

#Variable pour le reveil
heure = " "
min = " "
hReveil = "OFF"
mReveil = " "
reveilRegle = False

#Initialisation des LEDS
led.init(ledAllum)
led.init(ledReveil)

#On s'assure que les LEDS sont eteintes
led.turnOff(ledAllum)
led.turnOff(ledReveil)
cardNuit = []
##Pour la démo on a besoin d'avoir la nuit complete d'avance
li = [
    60.00, 59.00, 61.00, 60.00, 59.00, 56.00, 59.00, 61.00, 58.00, 58.00,
    58.00, 57.00, 59.00, 56.00, 60.00, 63.00, 61.00, 60.00, 61.00, 61.00,
    60.00, 60.00, 60.00, 60.00, 61.00, 60.00, 58.00, 65.00, 60.00, 61.00,
    62.00, 60.00, 58.00, 60.00, 60.00, 60.00, 59.00, 55.00, 57.00, 54.00,
    54.00, 54.00, 54.00, 55.00, 55.00, 59.00, 60.00, 60.00, 58.00, 56.00,
    56.00, 55.00, 55.00, 55.00, 55.00, 54.00, 53.00, 52.00, 53.00, 52.00,
    52.00, 53.00, 53.00, 52.00, 52.00, 53.00, 59.00, 63.00, 53.00, 57.00,
示例#5
0
pir_sensor = 8
motion=0
grovepi.pinMode(pir_sensor,"INPUT")

#Variables
light_sensor = 0
pinLed = 6
pinUltraSon = 4
loudness_sensor = 1 
button = 3


bool = True

#initialisation
led.init(pinLed)
led.offLED(pinLed)

#Init Ecran + affichage
setText("Luminosite 0")	
setRGB(20,20,20)


date = datetime.date.today()
compteur = 0
cout = 1 #a definir prix pour 1 seconde

mois = date.month
compteurMois = 0
cMois = 0
#!/usr/bin/env python
import led
import time

dev = led.init()

led.run(dev, [255] + [0]*63, timeout=2000)
def pwm_1led(index):
    i = led.LED_ARR[index]
    shift = i % 8;
    number = [1 << shift]
    col = [0]*(i/8)+number+[0]*((63-i)/8)
    return col
    
for col_nr in range(3):
    for i in range(64):
        col = pwm_1led(i)

        if col_nr == 0:
            data = (2*col + 32*[0])*led.NUM_ROWS
        elif col_nr == 1:
            data = (16*[0]+2*col + 16*[0])*led.NUM_ROWS
        else:
            data = (32*[0] + 2*col)*led.NUM_ROWS

        led.run(dev, data, timeout=5000)

if __name__ == '__main__':
    img = bytearray(led.ROW*led.NUM_ROWS);
    leds = [0]*360*128
    for col_nr in range(3):
        for i in range(64):
            col = pwm_1led(i)

            if col_nr == 0:
                data = (15*col + 240*[0])*128
            elif col_nr == 1:
                data = (120*[0]+15*col + 120*[0])*128
            else:
                data = (240*[0] + 15*col)*128
            #led.run(data)
            time.sleep(0.1)
            break
        break

    boards = led.init(find_all=True)
    threads = []
    for b in boards:
        print "found board", b
        t = Board(b, data)
        t.start()
        threads.append(t)

    for t in threads:
        t.join()
示例#8
0
import traceback

INTERVAL = 60  #do http req test interval


def ledOn(x, blink=False):
    '''to contrl led on or blink for 1 second, x should be within [0,8]'''
    byte = led.translate_led_to_byte(x)
    if blink:
        led.blink(byte)
    else:
        led.turn_on(byte)


if __name__ == "__main__":
    led.init()
    SAKS = SAKSHAT()
    web_checker = WebChecker(interval=INTERVAL, thread_pool_size=16)
    #Beeper to run in a thread, so that the beep and blink can be simultaneously
    beeper = Beeper()
    beeper.start()

    def showChecking():
        SAKS.digital_display.off()  #digital display off
        led.turn_on(0x0c)

    #initially read dip switch#2 to the flag
    status = SAKS.dip_switch.is_on
    beep_flag = status[1]

    #callback function when dip_switch status change to turn on/off beeper
示例#9
0
  temp = temperature.get()
  if temp > c['temp'] :
    if c['debug'] == 1 :
      print("temp: %.3f, over %.3f"%(temp, c['temp']))
    syslog.syslog(syslog.LOG_WARNING, "temp: %.3f, over %.3f"%(temp, c['temp']))
    led.control(1, c['gpio'])
  else :
    led.control(0, c['gpio'])
  time.sleep(c['time'])

def parentfunc():
  time.sleep(10)

def atexit_func() :
#  print("pid %d: exit!!"%(os.getpid()))
  syslog.closelog()

if __name__ == '__main__' :
  global c, f 
  atexit.register(atexit_func)
  f = fork.fork(pidfile="/var/run/cputempmon-py.pid")
  c = configs.configs(name=sys.argv[0], pidfile="/var/run/cputempmon-py.pid", stop=f.stop)
  c.getopt(sys.argv[1:])
  f['parent'] = parentfunc 
  f['child'] = childfunc 
  syslog.openlog("%s"%(os.path.basename(sys.argv[0])), syslog.LOG_LOCAL0 | syslog.LOG_PID)
  led.init(c['gpio'])
  f.run(c['bg'])


示例#10
0
def main():
    led.init()
    print " ++ Tic-Tac-GPIO! ++"

    while 2 + 2 == 4:
        playGame()