Skip to content

Instantly share code, notes, and snippets.

@iktakahiro
Last active October 9, 2015 07:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iktakahiro/f96fbaa0bac5576a6967 to your computer and use it in GitHub Desktop.
Save iktakahiro/f96fbaa0bac5576a6967 to your computer and use it in GitHub Desktop.

スイッチとLEDを連動

import mraa
import time

class Counter(object):
    count = 0

c = Counter()
def check_switch(args):

    if c.count % 2 == 0:
        led.write(1)
    else:
        led.write(0)

    c.count += 1

led = mraa.Gpio(6)
led.dir(mraa.DIR_OUT)

switch = mraa.Gpio(2)
switch.dir(mraa.DIR_IN)
switch.isr(mraa.EDGE_BOTH, check_switch, 1)

time.sleep(500)

明度が一定の値以下の場合にLED点灯

import mraa
import time

threthold = 400

light = mraa.Aio(1)

led = mraa.Gpio(6)
led.dir(mraa.DIR_OUT)

def check_light():

    print(light.read())

    if threthold > light.read():
        led.write(1)

    else:
        led.write(0)

while True:
    check_light()
    time.sleep(3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment