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 <= 1.2) {Voltage = 1.2;}
if (Voltage >= 2.4 && Voltage <= 5.0) {Voltage = 2.4;}
ir_length = 1/ ( 0.05 + ( ( Voltage - 1.3) * 0.05 ) );
//Serial.println(sensorValue);
Serial.print("130");
Serial.print(",");
Serial.print(Voltage*100);
Serial.print(",");
Serial.print("100");
Serial.print(",");
Serial.print(ir_length*10);
Serial.print(",");
Serial.print("200");
Serial.print(",");
Serial.println("230");
delay(10);
}
参考
配列化
#include <stdio.h>
int main(void){
int ii;
int s;
unsigned char pp[]={
200,199,198,197,196,196,195,194,193,193,
192,191,190,190,189,188,187,187,186,185,
185,184,183,183,182,181,181,180,179,179,
178,177,177,176,176,175,174,174,173,173,
172,171,171,170,170,169,168,168,167,167,
166,166,165,165,164,163,163,162,162,161,
161,160,160,159,159,158,158,157,157,156,
156,155,155,154,154,153,153,152,152,151,
151,151,150,150,149,149,148,148,147,147,
147,146,146,145,145,144,144,144,143,143,
142,142,142,141,141,140,140,140,139,139,
138,138,138,137,137,136,136,136,135,135,
135,134,134,134,133,133,132,132,132,131,
131,131,130,130,130,129,129,129,128,128,
128,127,127,127,126,126,126,125,125,125,
125,124,124,124,123,123,123,122,122,122,
121,121,121,121,120,120,120,119,119,119,
119,118,118,118,117,117,117,117,116,116,
116,116,115,115,115,114,114,114,114,113,
113,113,113,112,112,112,112,111,111,111,
111,110,110,110,110,109,109,109,109,108,
108,108,108,107,107,107,107,107,106,106,
106,106,105,105,105,105,105,104,104,104,
104,103,103,103,103,103,102,102,102,102,
102,101,101,101,101,101,100,100,100,100,
100
};
for(ii = 1300;ii <= 2300;ii=ii+4) {
s=(ii-1300)>>2;
printf("%d \t %d \n",ii,pp[s]);
}//ii
}//main
1300 200
1304 199
1308 198
1312 197
1316 196
1320 196
1324 195
1328 194
1332 193
1336 193
1340 192
1344 191
1348 190
1352 190
1356 189
1360 188
1364 187
1368 187
1372 186
1376 185
1380 185
1384 184
1388 183
1392 183
1396 182
1400 181
1404 181
1408 180
1412 179
1416 179
1420 178
1424 177
1428 177
1432 176
1436 176
1440 175
1444 174
1448 174
1452 173
1456 173
1460 172
1464 171
1468 171
1472 170
1476 170
1480 169
1484 168
1488 168
1492 167
1496 167
1500 166
1504 166
1508 165
1512 165
1516 164
1520 163
1524 163
1528 162
1532 162
1536 161
1540 161
1544 160
1548 160
1552 159
1556 159
1560 158
1564 158
1568 157
1572 157
1576 156
1580 156
1584 155
1588 155
1592 154
1596 154
1600 153
1604 153
1608 152
1612 152
1616 151
1620 151
1624 151
1628 150
1632 150
1636 149
1640 149
1644 148
1648 148
1652 147
1656 147
1660 147
1664 146
1668 146
1672 145
1676 145
1680 144
1684 144
1688 144
1692 143
1696 143
1700 142
1704 142
1708 142
1712 141
1716 141
1720 140
1724 140
1728 140
1732 139
1736 139
1740 138
1744 138
1748 138
1752 137
1756 137
1760 136
1764 136
1768 136
1772 135
1776 135
1780 135
1784 134
1788 134
1792 134
1796 133
1800 133
1804 132
1808 132
1812 132
1816 131
1820 131
1824 131
1828 130
1832 130
1836 130
1840 129
1844 129
1848 129
1852 128
1856 128
1860 128
1864 127
1868 127
1872 127
1876 126
1880 126
1884 126
1888 125
1892 125
1896 125
1900 125
1904 124
1908 124
1912 124
1916 123
1920 123
1924 123
1928 122
1932 122
1936 122
1940 121
1944 121
1948 121
1952 121
1956 120
1960 120
1964 120
1968 119
1972 119
1976 119
1980 119
1984 118
1988 118
1992 118
1996 117
2000 117
2004 117
2008 117
2012 116
2016 116
2020 116
2024 116
2028 115
2032 115
2036 115
2040 114
2044 114
2048 114
2052 114
2056 113
2060 113
2064 113
2068 113
2072 112
2076 112
2080 112
2084 112
2088 111
2092 111
2096 111
2100 111
2104 110
2108 110
2112 110
2116 110
2120 109
2124 109
2128 109
2132 109
2136 108
2140 108
2144 108
2148 108
2152 107
2156 107
2160 107
2164 107
2168 107
2172 106
2176 106
2180 106
2184 106
2188 105
2192 105
2196 105
2200 105
2204 105
2208 104
2212 104
2216 104
2220 104
2224 103
2228 103
2232 103
2236 103
2240 103
2244 102
2248 102
2252 102
2256 102
2260 102
2264 101
2268 101
2272 101
2276 101
2280 101
2284 100
2288 100
2292 100
2296 100
2300 100