星瞳实验室APP,快速收到回复
  • 我们只解决官方正版的OpenMV的问题(STM32),其他的分支有很多兼容问题,我们无法解决。
  • 如果有产品硬件故障问题,比如无法开机,论坛很难解决。可以直接找售后维修
  • 发帖子之前,请确认看过所有的视频教程,https://singtown.com/learn/ 和所有的上手教程http://book.openmv.cc/
  • 每一个新的提问,单独发一个新帖子
  • 帖子需要目的,你要做什么?
  • 如果涉及代码,需要报错提示全部代码文本,请注意不要贴代码图片
  • 必看:玩转星瞳论坛了解一下图片上传,代码格式等问题。
  • 麻烦找一下openmv控制红外遥控HX1838B接收头的程序,(NEC通讯协议)



    • 0_1608723593936_11a75e4a-6ce0-48f3-a82e-cae6d18331e9-image.png 就是这种红外遥控器的控制程序



    • 这个就是根据NEC通信协议,控制IO就行。



    • 这个是我几年前写的了。

      ir_remote.py

      import pyb
      from pyb import Pin, ExtInt
      
      default_remoter = {\
      69 : {"value": "1", "longtap": False}, \
      70 : {"value": "2", "longtap": False}, \
      71 : {"value": "3", "longtap": False}, \
      68 : {"value": "4", "longtap": False}, \
      64 : {"value": "5", "longtap": False}, \
      67 : {"value": "6", "longtap": False}, \
      7  : {"value": "7", "longtap": False}, \
      21 : {"value": "8", "longtap": False}, \
      9  : {"value": "9", "longtap": False}, \
      22 : {"value": "*", "longtap": False}, \
      25 : {"value": "0", "longtap": False}, \
      13 : {"value": "#", "longtap": False}, \
      24 : {"value": "up", "longtap": True}, \
      82 : {"value": "down", "longtap": True}, \
      8  : {"value": "left", "longtap": True}, \
      90 : {"value": "right", "longtap": True}, \
      28 : {"value": "OK", "longtap": False} \
      }
      
      class IRrecv:
          def __init__(self, pin, remoter = default_remoter):
              self.pin = pin
              self.command = None
              self.hold_time = 0
              self.remoter = remoter
              self.ext = ExtInt(pin, ExtInt.IRQ_FALLING, Pin.PULL_NONE, self.__receive)
          def read_pulse(self, value):
              start = pyb.micros()
              while self.pin.value() == value and pyb.elapsed_micros(start) < 50000:
                  pass
              return pyb.elapsed_micros(start)
          def read_byte(self):
              data = 0
              for i in range(8):
                  if abs(self.read_pulse(0) - 560) > 200:
                      return None
                  pulse = self.read_pulse(1)
                  if abs(pulse - 560 ) < 200:
                      pass
                  elif abs(pulse - 1690 ) < 300:
                      data = (1 << i) + data
                  else:
                      return None
              return data
          def __receive(self, line):
              self.ext.disable()
              if abs(self.read_pulse(0) - 9000 ) < 500:
                  pulse = self.read_pulse(1)
                  if abs(pulse - 2250) < 500:
                      if (not self.remoter) or self.remoter[self.command]["longtap"]:
                          self.hold_time += 1
                  elif abs(pulse - 4500) < 500:
                      custom_code = self.read_byte()
                      custom_code_complement = self.read_byte()
                      command_code = self.read_byte()
                      command_code_complement = self.read_byte()
                      if custom_code is not None and \
                      custom_code_complement is not None and \
                      command_code is not None and \
                      command_code_complement is not None:
                          if custom_code + custom_code_complement == 255 and \
                          command_code + command_code_complement == 255:
                              self.command = command_code
                              self.hold_time = 1
              self.ext.enable()
          def __read_raw_code__(self):
              command = self.command
              self.command = None
              return(command)
      
          def read(self):
              if self.hold_time == 0:
                  return None
              else:
                  key = self.remoter[self.command]["value"]
                  self.hold_time = 0
                  return key
      

      main.py

      from pyb import Pin
      import time
      from ir_remote import IRrecv
      
      ir = IRrecv(Pin("P6", Pin.IN))
      
      while(True):
          key = ir.read()
          if key:
              print(key)
          time.sleep_ms(100)