帮助Arduino的和模拟最小值最大值设置

帮助Arduino的和模拟最小值最大值设置

问题描述:

嘿,我有以下代码:帮助Arduino的和模拟最小值最大值设置

sVal = analogRead(potPin); // read the value from the sensor 
    valMin = min(sVal, 1); 
    valMax = max(sVal, 128); 
    constrain(sVal,valMin,valMax); 

    itoa(sVal, res, 10); 
    println(res); 
    println(" "); 
    delay(150); 
    clearScreen(); 

现在,出于某种原因,在GLCD屏幕上的输出几乎是不断1023 我想最小值电位器为1,最大值为128.

您的代码表示对最小,最大和约束函数缺乏了解。我建议你仔细阅读文档。

在此期间,这里是我认为你后:

sVal = analogRead(potPin); 
sVal = sVal/8 + 1; //scale value [0.. 1023] to [1.. 128] 

itoa(sVal, res, 10); 
println(res); 
println(" "); 
delay(150); 
clearScreen(); 
+0

谢谢,我重读它;) – 2010-06-21 08:29:26

也有一个范围映射功能已经在API,如:

res = map(analogRead(potPin), 0,1023, 1,128);