- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我刚刚使用 PiFace Digital element14 I/O 板设置了 Raspberry Pi。到目前为止,我已经按照几个步骤让它工作,这样我就可以连接 I/O 端口(控制 LED 并操作开关来做事)我写的 python 代码工作正常,我可以让它做事.
目前我只是在闲逛,感受在 Pi 上编程的感觉,并试图了解这些功能。我想为一个简单的 6 位二进制计数器设置一个状态机,当我告诉它时,它会向上和向下计数,我可以很容易地做到这一点。但是,当我尝试将其提升到一个新的水平并使用中断来设置状态时,我遇到了问题。
我关注了 Manual以及This Guide获取激活中断的代码。
我编写的代码执行时没有错误,但是,要么未检测到中断,要么它们什么都不做,我不确定是哪一个。我的代码如下。我知道 while 循环适用于“等待”和“计数”状态,因为我可以定义初始条件。它计数正确,所以我非常确定 while 循环没问题,只是没有状态变化。
import pifacedigitalio as pfio
import os
import time
def startCounter(event):
global state
state = 'counting'
print('counter started')
def stopCounter(event):
global state
state = 'waiting'
def stopProg(event):
global state
state = 'stop'
def resetCounter(event):
global state
state = 'reset'
def setLEDs(stateArray):
i = 0
for state in stateArray:
pfio.digital_write(i,state)
i = i + 1
def calcBools(count):
binString = bin(count).rsplit('0b')[1]
stringLength = len(binString)
zeroString = '0' * (8 - stringLength)
newString = zeroString + binString
i = 0
boolsOut = [0,0,0,0,0,0,0,0]
for bit in newString:
if bit == '1':
boolsOut[i] = 1
i = i + 1
return boolsOut
####################
### MAIN PROGRAM ###
####################
pfio.init()
pifacedigital = pfio.PiFaceDigital()
listener = pfio.InputEventListener(chip=pifacedigital)
signalDirection = pfio.IODIR_RISING_EDGE
listener.register(0, signalDirection, stopProg)
listener.register(1, signalDirection, startCounter)
listener.register(2, signalDirection, stopCounter)
listener.register(3, signalDirection, resetCounter)
listener.activate()
counter = 0
running = True
state = 'waiting'
setLEDs([0,0,0,0,0,0,0,0])
direction = 'up'
while(running):
if state == 'stop':
running = False
listener.deactivate()
counter = 0
elif state == 'waiting':
time.sleep(1)
print('waiting...')
elif state == 'counting':
if direction == 'up':
counter = counter + 1
else:
counter = counter - 1
if counter > 63:
direction = 'down'
elif counter == 0:
direction = 'up'
elif state == 'reset':
counter = 0
else:
time.sleep(0.1)
setLEDs(calcBools(counter))
print(counter)
time.sleep(0.25)
所以这段代码不起作用,我尝试了一些使用 pifacecommon 库也不起作用的东西,将一些代码行替换为:
import pifacecommon as pfc
readport = pfc.mcp23s17.GPIOA # I also tried GPIOB to no avail
listener = pfc.interrupts.PortEventListener(readport, 0)
在此之后,两种方法的监听器命令是相同的。与此同时,我尝试使用 pfc.mcp23s17.write 命令,但显然它不存在或类似的愚蠢借口。
在此先感谢您阅读本文,如果您做出回应,我们将更加感谢您,如果您对我有答案,我们将更加感谢您!
-本
编辑(已解决):我的回答在我一直提供的第二个链接的评论中 :( 结果我写的一切都正确,我只需要从终端而不是 IDLE3 运行文件。
最佳答案
所以我的问题的答案在 2nd link 的评论中我提供了整个时间。我需要做的就是从终端运行程序,而不是 IDLE3。
我认为原因在于 Linux 中处理中断的方式。 Linux ISR 不是真正的 ISR,处理器将 ISR 置于 sleep 模式,直到它被调用。谁能详细说明为什么 IDLE3 不支持中断?
关于python - Raspberry Pi 和 PiFace Digital 的中断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32429320/
我有一个运行 Raspbian 的 Raspberry Pi 1。我尝试在 Raspberry Pi 3 上运行 SD 卡,但它没有启动。 我已经阅读了有关升级 Raspberry Pi 2 安装以在
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a softwar
我目前正在尝试RadiusNetworks发布的Raspberry Pi iBeacon教程,网址为 http://developer.radiusnetworks.com/2013/10/09/ho
我的公司使用 Raspberry Pi 3 作为产品中的嵌入式 Controller 。用户不会优雅地关闭它,他们只是扳动一个开关。为避免损坏,/boot 和/root 文件系统是只读的。这似乎是防弹
如何使用 Raspberry Pi 作为 b/w USB Tethered 手机和路由器的桥接器,使用“以太网电缆 b/w Raspberry Pi 和路由器”和“USB 电缆 b/w 手机和 Ras
我关注了一个名为Creating an Electron Application for the Raspberry Pi的博客,内容涉及使用Buster OS在Raspberry Pi中启动Elec
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 7年前关闭。 Improve thi
我有一个树莓派,并且已经从 raspbmc.com 加载了最新的独立版本。在使用 XBMC 时,我看到 CPU 使用率始终在 90% 以上。查看 XBMC wiki 和常见问题解答后,脏区域似乎是减少
我现在正在做一个小项目。我希望 python 脚本在登录到 GUI 后自动运行。 我按照这里的步骤操作:https://www.raspberrypi.org/forums/view ... 91&t
我正在使用 Android Things 在 Raspberry Pi 上构建应用程序并且我有 7 inch touch screen ,但屏幕永远不会关闭。 是否可以像 Android 手机一样设置
我正在执行一组事件以确保 Redis 在一组嵌入式系统(包括 Raspberry PI)中运行良好。为了修复执行未对齐内存访问的 Redis 的某些代码路径(由于 Redis 3.2 中引入的更改),
我正在尝试使用 Tanuki Java Service Wrapper。 我使用的硬件是带有 Raspbian wheezy 发行版的 Raspberry Pi。 (见 http://www.rasp
我希望构建一个以全屏模式在 Raspberry Pi 上运行的应用程序。我已经尝试过 JavaFX 和基于 Swing 的应用程序,但性能非常糟糕。 在我开始使用 SDL( http://www.li
我的项目在/home/pi/app中 以npm start开头 启动操作系统后如何启动应用程序? ****西类牙文 Mi proyecto esta zh/home/pi/app Arranca la
我正在尝试安装 Kappelt gBridge在 Raspberry Pi 3 B 型上,使用本指南:https://doc.gbridge.io/selfHosted/hostItYourself.
我正在使用我的 Pi 作为文件服务器,最近当我登录时,我看到一条错误消息,指出 libarmmem.so(无法打开共享对象文件),尽管有一些建议运行 apt-get update + 升级它并没有带来
我正在尝试使用 Raspberry# 库通过 Raspberry PI 上的 GPIO 引脚(打开和关闭)执行基本任务。根据 github 上的示例:https://github.com/raspbe
如标题所述,我在将一些用户空间中断代码从另一个 armv7 嵌入式 linux 平台移植到 Raspberry Pi 2 Model B 时遇到问题。 我知道 wiringPi 库(并让它以这种方式工
我正在尝试为 Raspberry Pi B+ 交叉编译 Tensorflow-Lite。为此,我正在关注 these instructions来自官方网站,它们是: git clone https:/
我正在尝试使用 PulseAudio RTP 将音频从 Linux Mint 桌面流式传输到运行 LibreELEC (Kodi) 的 RaspberryPi 3B。我可以使用 RTP 多播成功地流式
我是一名优秀的程序员,十分优秀!