Arduino电位器时间控制
Arduino potentiometer time control
我想通过电位器设置一个时间间隔。我想在1到6秒之间选择。我该怎么做呢?
到目前为止我有这个。如果我使用电位器,光就会由亮变暗。
(我使用Arduino Uno和我在c++编程)。
const byte pot = 0;
int potWert=0;
potWert = analogRead(pot);
analogWrite(led,potWert/4);
Serial.println((byte)potWert); //just for output on the serial monitor
analoread读取范围0到1023。您需要将其缩放到您的时间间隔
你说你想要的范围是1到6秒(不是0到6?)要使其适当地缩放到锅中,您需要将1023除以6(如果需要范围为0到6,则为7)。
1023 / 6 = 170.5
因此你需要使用:
analogWrite(led,potWert/170.5);
假设你想要精确到10毫秒单位
1023 / 600 = 1.705
:
analogWrite(led,potWert/1.705);
这是一种困难的方法,使代码难以阅读。使用map语句。下面是Arduino参考中的一个示例:
例子/* Map an analog value to 8 bits (0 to 255) */
void setup() {}
void loop()
{
int val = analogRead(0);
val = map(val, 0, 1023, 0, 255);
analogWrite(9, val);
}
相关文章:
- C++为构建时间获取QDateTime的可靠方法
- 从持续时间构造std::chrono::system_clock::time_point
- 向量 <int> a {N, 0} 和 int arr a[N] = {0} 的时间复杂度有什么区别
- while循环中while循环的时间复杂度是多少
- 使用简单类型列表实现的指数编译时间.为什么
- 是否可以在编译时初始化数组,以便在运行时不会花费时间?
- 在已经使用Git的情况下减少编译时间
- 有没有一种方法可以创建一个带有哈希表的数据库,该哈希表具有恒定时间查找功能
- 如何将包含epoch时间的十六进制字符串转换为time_t
- 控制允许动态运行c++的并发操作数
- 从控制台中删除最后打印的元素
- 从文本文件中读取时钟时间和事件时间并进行处理
- 具有未知值时的时间复杂性
- 通过休眠控制循环时间
- 哪种控制结构所需的时间复杂度更低?
- 如何控制Microsoft的 OpenMP 自旋锁时间?
- 使用 c++ qt 控制动画之间的时间间隔的方法
- 有没有办法控制英特尔线程构建模块中的线程数量、亲和力和创建时间
- 控制QTimer的时间
- Arduino电位器时间控制