“光电门传感器”的版本间的差异
来自Labplus盛思维基百科
Tangliufeng(讨论 | 贡献) (创建页面,内容为“ 400px|缩略图|右 |blue:bit-力传感器<br /> == 概述 == Photogate Time是测量触发时刻和触发结束时刻的时间模块…”) |
Tangliufeng(讨论 | 贡献) |
||
第43行: | 第43行: | ||
| <small>GND</small> || <small>地</small> | | <small>GND</small> || <small>地</small> | ||
|} | |} | ||
+ | |||
+ | * 可调电位器:调节触发信号的触发电平 | ||
== 使用教程 == | == 使用教程 == | ||
第51行: | 第53行: | ||
=== <font size=3px>Arduino</font> === | === <font size=3px>Arduino</font> === | ||
− | {{ | + | <syntaxhighlight lang="Python" line='line'> |
+ | |||
+ | #include <Wire.h> | ||
+ | int reading = 0; | ||
+ | int reading0 = 0; | ||
+ | int reading1 = 0; | ||
+ | int reading2 = 0; | ||
+ | int reading3 = 0; | ||
+ | int reading4 = 0; | ||
+ | long trigger_begin; | ||
+ | long trigger_end; | ||
+ | float trigger_time; | ||
+ | void Get_Photogate_value(char address) | ||
+ | { | ||
+ | Wire.requestFrom(0x51, 5); | ||
+ | if (5 <= Wire.available()) | ||
+ | { | ||
+ | reading0 = Wire.read(); | ||
+ | reading1 = Wire.read(); | ||
+ | reading2 = Wire.read(); | ||
+ | reading3 = Wire.read(); | ||
+ | reading4 = Wire.read(); | ||
+ | if(reading0==1) | ||
+ | { | ||
+ | trigger_begin = reading1*16777216 + reading2*65536 + reading3*256 + reading4; | ||
+ | //Serial.println(1); | ||
+ | //Serial.println(trigger_begin); | ||
+ | } | ||
+ | if(reading0==0) | ||
+ | { | ||
+ | trigger_end = reading1*16777216 + reading2*65536 + reading3*256 + reading4; | ||
+ | //Serial.println(0); | ||
+ | //Serial.println(trigger_end); | ||
+ | trigger_time = (float)(trigger_end - trigger_begin)/2041667; //250000 2041667 | ||
+ | Serial.println(trigger_time); | ||
+ | } | ||
+ | |||
+ | } | ||
+ | void setup() | ||
+ | { | ||
+ | Wire.begin(); // join i2c bus (address optional for master) | ||
+ | Serial.begin(9600); // start serial for output | ||
+ | } | ||
+ | |||
+ | void loop() | ||
+ | { | ||
+ | Get_Photogate_value(0x51); | ||
+ | } | ||
+ | |||
+ | </syntaxhighlight> | ||
=== <font size=3px>掌控板</font> === | === <font size=3px>掌控板</font> === | ||
− | {{ | + | * GitHub:[https://github.com/labplus-cn/mPython_bluebit bluebit for mPython library] |
+ | * bluebit for mPython library API: https://mpython-lib.readthedocs.io/zh/master/bluebit/index.html | ||
+ | |||
+ | <syntaxhighlight lang="Python" line='line'> | ||
+ | |||
+ | |||
+ | } | ||
+ | void setup() | ||
+ | { | ||
+ | Wire.begin(); // join i2c bus (address optional for master) | ||
+ | Serial.begin(9600); // start serial for output | ||
+ | } | ||
+ | |||
+ | void loop() | ||
+ | { | ||
+ | Get_Photogate_value(0x51); | ||
+ | } | ||
+ | |||
+ | </syntaxhighlight> | ||
=== <font size=3px>microbit</font> === | === <font size=3px>microbit</font> === |
2019年4月18日 (四) 11:28的版本
概述
Photogate Time是测量触发时刻和触发结束时刻的时间模块。
技术参数
- 工作电压:VCC 3.3-5V
- I2C数字信号输出
- 时间范围 : 0~
- 解析度: 10微秒
- 精度: 2%
- 模块尺寸:24x46x7.5mm
引脚定义/接口说明
VCC | 电源 |
SDA | I2C数据 |
SCL | I2C时钟 |
GND | 地 |
|
- 触发信号的输入接口
VCC | 电源 |
CH0 | NA(未用) |
CH1 | 触发信号输入 |
GND | 地 |
- 可调电位器:调节触发信号的触发电平
使用教程
- 在程序编程中需要注意拨动开关地址和程序中的地址一致!
- 计算信号的正脉宽时间,当输入信号由低变高为触发开始点,由高变低位触发触发结束点,计算之间的时间差。
Arduino
#include <Wire.h>
int reading = 0;
int reading0 = 0;
int reading1 = 0;
int reading2 = 0;
int reading3 = 0;
int reading4 = 0;
long trigger_begin;
long trigger_end;
float trigger_time;
void Get_Photogate_value(char address)
{
Wire.requestFrom(0x51, 5);
if (5 <= Wire.available())
{
reading0 = Wire.read();
reading1 = Wire.read();
reading2 = Wire.read();
reading3 = Wire.read();
reading4 = Wire.read();
if(reading0==1)
{
trigger_begin = reading1*16777216 + reading2*65536 + reading3*256 + reading4;
//Serial.println(1);
//Serial.println(trigger_begin);
}
if(reading0==0)
{
trigger_end = reading1*16777216 + reading2*65536 + reading3*256 + reading4;
//Serial.println(0);
//Serial.println(trigger_end);
trigger_time = (float)(trigger_end - trigger_begin)/2041667; //250000 2041667
Serial.println(trigger_time);
}
}
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600); // start serial for output
}
void loop()
{
Get_Photogate_value(0x51);
}
掌控板
- GitHub:bluebit for mPython library
- bluebit for mPython library API: https://mpython-lib.readthedocs.io/zh/master/bluebit/index.html
}
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600); // start serial for output
}
void loop()
{
Get_Photogate_value(0x51);
}
microbit
应用案例
FAQ
版本历史记录
Version | Date | 新增/删除/修复 |
---|---|---|