Ejemplo n.º 1
0
def start():
    global SAKS
    global beeper
    global led
    led = Led()
    SAKS = SAKSHAT()
    beeper = Beeper(SAKS)
    beeper.start()
Ejemplo n.º 2
0
Archivo: rpi.py Proyecto: asdlei99/mypi
    def init(self):
        self.SAKS = SAKSHAT()

        # 在检测到轻触开关触发时自动执行此函数
        def tact_event_handler(pin, status):
            print pin, status
            # 停止闹钟响铃(按下任何轻触开关均可触发)
            self.__alarm_beep_status = False
            self.__alarm_beep_times = 0
            self.SAKS.buzzer.off()
            self.SAKS.ledrow.off_for_index(6)

        self.SAKS.tact_event_handler = tact_event_handler
        self.SAKS.buzzer.off()
        self.SAKS.ledrow.off_for_index(6)
Ejemplo n.º 3
0
#!/bin/env python
#coding:utf-8
from sakshat import SAKSHAT
import threading
import time
SAKS = SAKSHAT()


class Beeper(threading.Thread):
    '''to make it beep and blink at the same time, this should be in another thread'''
    def run(self):
        self.beep = False
        self.stop = False
        while not self.stop:
            if self.beep:
                self.beep = False
                SAKS.buzzer.beepAction(0.02, 0.02, 30)
            time.sleep(0.1)
Ejemplo n.º 4
0
from sakshat import SAKSHAT

from sakspins import SAKSPins as PINS

SAKS = SAKSHAT()

global h

global m

h = 0

m = 0

def tact_event_handler():

    global h

    global m

    if SAKS.dip_switch.is_on[0] == True and SAKS.dip_switch.is_on[1]==True:

        h+=1

    if SAKS.dip_switch.is_on[0] == False and SAKS.dip_switch.is_on[1]==True:

        m+=1

    if SAKS.dip_switch.is_on[0] == True and SAKS.dip_switch.is_on[1] == False:

        h-=1
Ejemplo n.º 5
0
# coding=utf-8
# 反应测试游戏
# 游戏介绍:游戏开始后,蜂鸣器会随机响起,玩家在听到声音后立刻按下按键,从而测试玩家的反应速度,
# 在三次游戏后数码管上会显示玩家最终得分,反应速度越快得分越高
from sakshat import SAKSHAT
import time
import random
import math

SAKS = SAKSHAT()
buz = SAKS.buzzer
ledr = SAKS.ledrow
digr = SAKS.digital_display
tactr = SAKS.tactrow

# 蜂鸣器响五声,LED灯全亮,数码管显示0000,3秒后一起熄灭,提醒玩家游戏开始
buz.beepAction(0.2, 0.2, 5)
ledr.on()
digr.show("0000")
time.sleep(3)
ledr.off()
digr.off()


def tact(pin, status):  #设置按键动作
    if status:
        actt = time.time()  #记录按下按键的时刻
        gap = actt - prest  #用按下按键的时间减去蜂鸣器响起的时间作为反应时间
        print(gap)
        a = (math.floor(gap)) % 10  #算出反应时间各位数字
        b = (math.floor(10 * gap)) % 10
Ejemplo n.º 6
0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# tutorials url: http://shumeipai.nxez.com/2015/10/24/saks-diy-tutorials-nightlight.html

__author__ = 'Spoony'
__license__  = 'Copyright (c) 2015 NXEZ.COM'

from sakshat import SAKSHAT
from sakspins import SAKSPins as PINS
import time

#Declare the SAKS Board
SAKS = SAKSHAT()
#当前开关状态
__light_status = False

#在检测到拨码开关状态被修改时自动执行此函数
def dip_switch_status_changed_handler(status):
    '''
    called while the status of dip switch changed
    :param status: current status
    :return: void
    '''
    global __light_status
    #在小灯状态开着时执行
    if __light_status:
        #拨码开关第1位状态为ON
        if status[0]:
Ejemplo n.º 7
0
    else:
        index = second / 10 + 1
        if (model == 0):
            light_low(index)
        else:
            saks.ledrow.off()
            saks.ledrow.on_for_index(8 - int(index))


def timer(model):
    while True:
        time_value = time.localtime()
        time_second = time.strftime("%S", time_value)
        time_show = time.strftime("%H.%M", time_value)
        saks.digital_display.show(time_show)

        show_seconds(model, time_second)
        time.sleep(1)


if __name__ == '__main__':

    MODEL = 0
    if len(sys.argv) >= 2:
        MODEL = 1
    # print("model is %d" % model)
    # print(len(sys.argv))

    saks = SAKSHAT()
    timer(MODEL)
Ejemplo n.º 8
0
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
    def dipStatus(status):
Ejemplo n.º 9
0
import time
import sys
from sakshat import SAKSHAT
import subprocess  #python3 replace commands package with subprocess
import Adafruit_DHT

if __name__ == '__main__':

    saks = SAKSHAT()
    saks.saks_gpio_init()
    sensor = Adafruit_DHT.DHT11
    pin = 24
    hu, temp = Adafruit_DHT.read_retry(sensor, pin)
    print('温度:{0:0.1f}°C 湿度:{1:0.1f}%'.format(temp, hu))

    try:
        print('开始测量温度')
        # 循环
        while True:
            try:
                hu, temp = Adafruit_DHT.read_retry(sensor, pin)
                print('温度:{0:0.1f}°C 湿度:{1:0.1f}%'.format(temp, hu))
                time.sleep(2)
            except RuntimeError as e:
                print("error\n{0}".format(e))
                time.sleep(10)
            except:
                print("error\nFailed to read sensor data!")
                time.sleep(10)
    finally:
        print("clean up in finally")
Ejemplo n.º 10
0
import pygame
from pygame import *
import time
from sakshat import SAKSHAT
from sakspins import SAKSPins as PINS
import random
import RPi.GPIO as GPIO

#screen = pygame.display.set_mode((640, 480), 0, 32)

GPIO.setmode(GPIO.BCM)  #采用BCM编码模式
SAKS = SAKSHAT()  #调用SAKSHAT模块
DS = 6  # 控制LED灯的三个端口的BCM编码
SHCP = 19
STCP = 13

speed = 0.36  # set speed


def init():  # 初始化端口状态

    GPIO.setup(DS, GPIO.OUT)
    GPIO.setup(SHCP, GPIO.OUT)
    GPIO.setup(STCP, GPIO.OUT)

    GPIO.output(DS, GPIO.LOW)
    GPIO.output(SHCP, GPIO.LOW)
    GPIO.output(STCP, GPIO.LOW)


# 实现1到8对应流水灯的状态,i对应从左到右前i个LED灯亮
Ejemplo n.º 11
0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# tutorials url: http://shumeipai.nxez.com/2015/10/11/saks-diy-tutorials-digital-clock.html

__author__ = 'Spoony'
__license__  = 'Copyright (c) 2015 NXEZ.COM'

from sakshat import SAKSHAT
import time

#Declare the SAKS Board
SAKS = SAKSHAT()

__dp = True
__alarm_beep_status = False
__alarm_beep_times = 0
# 在这里设定闹钟定时时间
__alarm_time = "18:10:00"

#在检测到轻触开关触发时自动执行此函数
def tact_event_handler(pin, status):
    '''
    called while the status of tacts changed
    :param pin: pin number which stauts of tact is changed
    :param status: current status
    :return: void
    '''
Ejemplo n.º 12
0
    :param pin: pin number which stauts of tact is changed
    :param status: current status
    :return: void
    '''
    # print('tact_event_handler')
    # print("%d - %s" % (pin, status))
    if status != True:
        # print('status is true')
        return

    # print("pin %d" % pin)
    saks.ledrow.off()
    if (pin == 16):
        # print("pin 16")
        show_temp_or_wet(1)
        saks.ledrow.on_for_index(0)
    else:
        # print("pin %d" % pin)
        show_temp_or_wet(2)
        saks.ledrow.on_for_index(7)


if __name__ == '__main__':
    saks = SAKSHAT()
    sensor = Adafruit_DHT.DHT11
    pin = 24

    saks.tact_event_handler = tact_event_handler
    while True:
        get_temp_or_wet()
        time.sleep(1)
Ejemplo n.º 13
0
from sakshat import SAKSHAT
from sakshat.sakspins import SAKSPins as PINS
from datetime import timedelta
import threading, time, sched, random, datetime
from threading import Timer  #导入各种需要用到的模块
SAKS = SAKSHAT()
timelist = []
ledlist = []  #建立基本的用于存储的列表和字符串
sled = ''


def tact_event_handler(pin, status):  #该函数表示当轻触按钮状态改变时,对应要完成的指令
    global timelist
    global ledlist
    global tlist
    global sled  #这里我们把所有在引用函数里用到的存储列表全局化
    ######################################################################输入阶段############################################################
    if pin == PINS.TACT_LEFT and status == True:  #当左轻触按钮被按下(需要注意的是,对于轻触按钮来讲,按下和松开都是状态改变,我们只以按下计次)
        timelist.append(datetime.datetime.now())  #使用datetime记录当前时间点
        SAKS.buzzer.beep(0.05)  #蜂鸣器在轻触按钮按下时鸣叫0.05秒以与体验者互动
        sled = str(random.randrange(
            0, 8)) + sled  #与此同时,生成与按下次数相同长度的LED亮起随机顺序表,以字符串形式存储

    ######################################################################处理阶段############################################################
    elif pin == PINS.TACT_RIGHT and status == True:  #当右轻触按钮被按下,输入过程结束
        tem = timelist[0]
        timelist = [(i - tem) for i in timelist
                    ]  #首先将时间点列表中的时间点转换为timedelta 格式,表示与第一下按下的时间间隔
        tlist = [(i.seconds + i.microseconds / 1000000)
                 for i in timelist]  #转化为秒为单位的数字
        sled = '---' + sled + '0'  #将led随机亮序补位,前面的---使得轮到最后一位数字到最右一位数码管时表示方便,末尾补位0方便切片
from sakshat import SAKSHAT
import time
import threading
from last_my_send import send_email
from last_my_recieve import recieve_email
from light_on import *
from chr_to_mp3 import change
touch_n = 0
display_n = 0
list_message = []
list_light = [0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80]
SAKS = SAKSHAT()


def alarm_on():
    SAKS.buzzer.on()
    SAKS.ledrow.on_for_index(6)
    time.sleep(0.05)
    SAKS.buzzer.off()
    SAKS.ledrow.off_for_index(6)


def display_on(*args):
    if not args:
        a = list(time.localtime())[3]
        b = list(time.localtime())[4]
        SAKS.digital_display.show(("%02d%02d." % (a, b)))
    else:
        a, b = args
        SAKS.digital_display.show(("%02d%02d." % (a, b)))
Ejemplo n.º 15
0
'''
通过树莓派获取CPU 和GPU的温度

'''
def dip_switch_status_changed_handler(status):
    '''
    called while the status of dip switch changed
    :param status: current status
    :return: void
    '''
    print('on_dip_switch_status_changed:')
    print(status)
    pass

def tact_event_handler(pin, status):
    '''
    called while the status of tacts changed
    :param pin: pin number which stauts of tact is changed
    :param status: current status
    :return: void
    '''
    print('tact_event_handler')
    print("%d - %s" % (pin, status))

if __name__ == '__main__':
    saks = SAKSHAT()
    saks.dip_switch_status_changed_handler = dip_switch_status_changed_handler
    saks.tact_event_handler = tact_event_handler

    while True:
        time.sleep(1)