x気になる人よう
目的
adcのテスト用
式が難しく、範囲が広いために分割してテストしてます。あしからず。
式が正しいことが分かった。
void setup() {
Serial.begin(9600);
}
int sensorValue; //センサーの読み取り値
float Voltage; //電圧
float ir_length; //長さ
void loop() {
sensorValue = analogRead(A0);
Voltage = (float)sensorValue * ( 5.0 / 1024.0 );
if (Voltage >= 0 && Voltage <= 2.2) {Voltage = 2.2;}
if (Voltage >= 3.22 && Voltage <= 5.0) {Voltage = 3.22;}
if (Voltage >= 2.3 && Voltage <= 2.75) { //10-8
ir_length = 1.0/ ( 0.1 + ( ( Voltage - 2.3) * (0.025/0.45) ) );
} else if (Voltage >= 2.75 && Voltage <= 2.98) { //8-7
ir_length = 1.0/ ( 0.125 + ( ( Voltage - 2.75) * (0.0179/0.23) ) );
} else if (Voltage >= 2.98 && Voltage <= 3.12) { //7-6
ir_length = 1.0/ ( 0.1429 + ( ( Voltage - 2.98) * (0.0238/0.14) ) );
}
//Serial.println(sensorValue);
Serial.print("230");
Serial.print(",");
Serial.print( Voltage*100);
Serial.print(",");
Serial.print("312");
Serial.print(",");
Serial.print("60");
Serial.print(",");
Serial.print( ir_length*10 );
Serial.print(",");
Serial.println("100");
delay(10);
}
配列化
#include <stdio.h>
int main(void){
int ii;
int s=0;
unsigned char oo[]={
100,99,98,98,97,97,96,96,95,95,
94,94,93,93,92,92,91,91,90,90,
90,89,89,88,88,87,87,86,86,86,
85,85,84,84,84,83,83,82,82,82,
81,81,81,80,80,80,79,79,78,78,
77,77,76,76,75,75,74,74,74,73,
73,72,72,71,71,71,70,70,69,69,
68,67,66,66,65,64,63,63,62,61,
61,60,60
};
for(ii = 2300;ii <= 3120;ii=ii+10) {
s=(ii-2300)/10;
printf("%d \t %d \n",ii,oo[s]);
}//ii
}//main
2300 100
2310 99
2320 98
2330 98
2340 97
2350 97
2360 96
2370 96
2380 95
2390 95
2400 94
2410 94
2420 93
2430 93
2440 92
2450 92
2460 91
2470 91
2480 90
2490 90
2500 90
2510 89
2520 89
2530 88
2540 88
2550 87
2560 87
2570 86
2580 86
2590 86
2600 85
2610 85
2620 84
2630 84
2640 84
2650 83
2660 83
2670 82
2680 82
2690 82
2700 81
2710 81
2720 81
2730 80
2740 80
2750 80
2760 79
2770 79
2780 78
2790 78
2800 77
2810 77
2820 76
2830 76
2840 75
2850 75
2860 74
2870 74
2880 74
2890 73
2900 73
2910 72
2920 72
2930 71
2940 71
2950 71
2960 70
2970 70
2980 69
2990 69
3000 68
3010 67
3020 66
3030 66
3040 65
3050 64
3060 63
3070 63
3080 62
3090 61
3100 61
3110 60
3120 60