センサーの値0...1023を0...約5Vに変換してあそぶ(39.0625掛けて8で割る)(オンラインコンパイラ)


参考

https://qiita.com/caa45040/items/09848d08a81b0d157458

目的
センサーの値を電圧に変換する
とりあえずまず、オンラインコンパイラで試す。


s = (s * 39.0625) / 8
例
5000 = (1024 * 39.0625) /8

結果

![o_coq302.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/840352/90e42491-7a69-82d0-7a82-49da508382ef.jpeg)


プログラム

オンラインコンパイラ


```c++

#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    printf("START\n");
    
    unsigned short vo;
    for(int s=0;s<1025;s++){
        
        vo = s;
        
        vo = ((vo * 39U)+(vo >> 4))>>3;
        
        printf("(%d)[%d]\n",s,vo);
        
    }//for
    printf("\n");
}//main


```

```

START
(0)[0]
(1)[4]
(2)[9]
(3)[14]
(4)[19]
(5)[24]
(6)[29]
(7)[34]
(8)[39]
(9)[43]
(10)[48]
(11)[53]
(12)[58]
(13)[63]
(14)[68]
(15)[73]
(16)[78]
(17)[83]
(18)[87]
(19)[92]
(20)[97]
(21)[102]
(22)[107]
(23)[112]
(24)[117]
(25)[122]
(26)[126]
(27)[131]
(28)[136]
(29)[141]
(30)[146]
(31)[151]
(32)[156]
(33)[161]
(34)[166]
(35)[170]
(36)[175]
(37)[180]
(38)[185]
(39)[190]
(40)[195]
(41)[200]
(42)[205]
(43)[209]
(44)[214]
(45)[219]
(46)[224]
(47)[229]
(48)[234]
(49)[239]
(50)[244]
(51)[249]
(52)[253]
(53)[258]
(54)[263]
(55)[268]
(56)[273]
(57)[278]
(58)[283]
(59)[288]
(60)[292]
(61)[297]
(62)[302]
(63)[307]
(64)[312]
(65)[317]
(66)[322]
(67)[327]
(68)[332]
(69)[336]
(70)[341]
(71)[346]
(72)[351]
(73)[356]
(74)[361]
(75)[366]
(76)[371]
(77)[375]
(78)[380]
(79)[385]
(80)[390]
(81)[395]
(82)[400]
(83)[405]
(84)[410]
(85)[415]
(86)[419]
(87)[424]
(88)[429]
(89)[434]
(90)[439]
(91)[444]
(92)[449]
(93)[454]
(94)[458]
(95)[463]
(96)[468]
(97)[473]
(98)[478]
(99)[483]
(100)[488]
(101)[493]
(102)[498]
(103)[502]
(104)[507]
(105)[512]
(106)[517]
(107)[522]
(108)[527]
(109)[532]
(110)[537]
(111)[541]
(112)[546]
(113)[551]
(114)[556]
(115)[561]
(116)[566]
(117)[571]
(118)[576]
(119)[581]
(120)[585]
(121)[590]
(122)[595]
(123)[600]
(124)[605]
(125)[610]
(126)[615]
(127)[620]
(128)[625]
(129)[629]
(130)[634]
(131)[639]
(132)[644]
(133)[649]
(134)[654]
(135)[659]
(136)[664]
(137)[668]
(138)[673]
(139)[678]
(140)[683]
(141)[688]
(142)[693]
(143)[698]
(144)[703]
(145)[708]
(146)[712]
(147)[717]
(148)[722]
(149)[727]
(150)[732]
(151)[737]
(152)[742]
(153)[747]
(154)[751]
(155)[756]
(156)[761]
(157)[766]
(158)[771]
(159)[776]
(160)[781]
(161)[786]
(162)[791]
(163)[795]
(164)[800]
(165)[805]
(166)[810]
(167)[815]
(168)[820]
(169)[825]
(170)[830]
(171)[834]
(172)[839]
(173)[844]
(174)[849]
(175)[854]
(176)[859]
(177)[864]
(178)[869]
(179)[874]
(180)[878]
(181)[883]
(182)[888]
(183)[893]
(184)[898]
(185)[903]
(186)[908]
(187)[913]
(188)[917]
(189)[922]
(190)[927]
(191)[932]
(192)[937]
(193)[942]
(194)[947]
(195)[952]
(196)[957]
(197)[961]
(198)[966]
(199)[971]
(200)[976]
(201)[981]
(202)[986]
(203)[991]
(204)[996]
(205)[1000]
(206)[1005]
(207)[1010]
(208)[1015]
(209)[1020]
(210)[1025]
(211)[1030]
(212)[1035]
(213)[1040]
(214)[1044]
(215)[1049]
(216)[1054]
(217)[1059]
(218)[1064]
(219)[1069]
(220)[1074]
(221)[1079]
(222)[1083]
(223)[1088]
(224)[1093]
(225)[1098]
(226)[1103]
(227)[1108]
(228)[1113]
(229)[1118]
(230)[1123]
(231)[1127]
(232)[1132]
(233)[1137]
(234)[1142]
(235)[1147]
(236)[1152]
(237)[1157]
(238)[1162]
(239)[1166]
(240)[1171]
(241)[1176]
(242)[1181]
(243)[1186]
(244)[1191]
(245)[1196]
(246)[1201]
(247)[1206]
(248)[1210]
(249)[1215]
(250)[1220]
(251)[1225]
(252)[1230]
(253)[1235]
(254)[1240]
(255)[1245]
(256)[1250]
(257)[1254]
(258)[1259]
(259)[1264]
(260)[1269]
(261)[1274]
(262)[1279]
(263)[1284]
(264)[1289]
(265)[1293]
(266)[1298]
(267)[1303]
(268)[1308]
(269)[1313]
(270)[1318]
(271)[1323]
(272)[1328]
(273)[1333]
(274)[1337]
(275)[1342]
(276)[1347]
(277)[1352]
(278)[1357]
(279)[1362]
(280)[1367]
(281)[1372]
(282)[1376]
(283)[1381]
(284)[1386]
(285)[1391]
(286)[1396]
(287)[1401]
(288)[1406]
(289)[1411]
(290)[1416]
(291)[1420]
(292)[1425]
(293)[1430]
(294)[1435]
(295)[1440]
(296)[1445]
(297)[1450]
(298)[1455]
(299)[1459]
(300)[1464]
(301)[1469]
(302)[1474]
(303)[1479]
(304)[1484]
(305)[1489]
(306)[1494]
(307)[1499]
(308)[1503]
(309)[1508]
(310)[1513]
(311)[1518]
(312)[1523]
(313)[1528]
(314)[1533]
(315)[1538]
(316)[1542]
(317)[1547]
(318)[1552]
(319)[1557]
(320)[1562]
(321)[1567]
(322)[1572]
(323)[1577]
(324)[1582]
(325)[1586]
(326)[1591]
(327)[1596]
(328)[1601]
(329)[1606]
(330)[1611]
(331)[1616]
(332)[1621]
(333)[1625]
(334)[1630]
(335)[1635]
(336)[1640]
(337)[1645]
(338)[1650]
(339)[1655]
(340)[1660]
(341)[1665]
(342)[1669]
(343)[1674]
(344)[1679]
(345)[1684]
(346)[1689]
(347)[1694]
(348)[1699]
(349)[1704]
(350)[1708]
(351)[1713]
(352)[1718]
(353)[1723]
(354)[1728]
(355)[1733]
(356)[1738]
(357)[1743]
(358)[1748]
(359)[1752]
(360)[1757]
(361)[1762]
(362)[1767]
(363)[1772]
(364)[1777]
(365)[1782]
(366)[1787]
(367)[1791]
(368)[1796]
(369)[1801]
(370)[1806]
(371)[1811]
(372)[1816]
(373)[1821]
(374)[1826]
(375)[1831]
(376)[1835]
(377)[1840]
(378)[1845]
(379)[1850]
(380)[1855]
(381)[1860]
(382)[1865]
(383)[1870]
(384)[1875]
(385)[1879]
(386)[1884]
(387)[1889]
(388)[1894]
(389)[1899]
(390)[1904]
(391)[1909]
(392)[1914]
(393)[1918]
(394)[1923]
(395)[1928]
(396)[1933]
(397)[1938]
(398)[1943]
(399)[1948]
(400)[1953]
(401)[1958]
(402)[1962]
(403)[1967]
(404)[1972]
(405)[1977]
(406)[1982]
(407)[1987]
(408)[1992]
(409)[1997]
(410)[2001]
(411)[2006]
(412)[2011]
(413)[2016]
(414)[2021]
(415)[2026]
(416)[2031]
(417)[2036]
(418)[2041]
(419)[2045]
(420)[2050]
(421)[2055]
(422)[2060]
(423)[2065]
(424)[2070]
(425)[2075]
(426)[2080]
(427)[2084]
(428)[2089]
(429)[2094]
(430)[2099]
(431)[2104]
(432)[2109]
(433)[2114]
(434)[2119]
(435)[2124]
(436)[2128]
(437)[2133]
(438)[2138]
(439)[2143]
(440)[2148]
(441)[2153]
(442)[2158]
(443)[2163]
(444)[2167]
(445)[2172]
(446)[2177]
(447)[2182]
(448)[2187]
(449)[2192]
(450)[2197]
(451)[2202]
(452)[2207]
(453)[2211]
(454)[2216]
(455)[2221]
(456)[2226]
(457)[2231]
(458)[2236]
(459)[2241]
(460)[2246]
(461)[2250]
(462)[2255]
(463)[2260]
(464)[2265]
(465)[2270]
(466)[2275]
(467)[2280]
(468)[2285]
(469)[2290]
(470)[2294]
(471)[2299]
(472)[2304]
(473)[2309]
(474)[2314]
(475)[2319]
(476)[2324]
(477)[2329]
(478)[2333]
(479)[2338]
(480)[2343]
(481)[2348]
(482)[2353]
(483)[2358]
(484)[2363]
(485)[2368]
(486)[2373]
(487)[2377]
(488)[2382]
(489)[2387]
(490)[2392]
(491)[2397]
(492)[2402]
(493)[2407]
(494)[2412]
(495)[2416]
(496)[2421]
(497)[2426]
(498)[2431]
(499)[2436]
(500)[2441]
(501)[2446]
(502)[2451]
(503)[2456]
(504)[2460]
(505)[2465]
(506)[2470]
(507)[2475]
(508)[2480]
(509)[2485]
(510)[2490]
(511)[2495]
(512)[2500]
(513)[2504]
(514)[2509]
(515)[2514]
(516)[2519]
(517)[2524]
(518)[2529]
(519)[2534]
(520)[2539]
(521)[2543]
(522)[2548]
(523)[2553]
(524)[2558]
(525)[2563]
(526)[2568]
(527)[2573]
(528)[2578]
(529)[2583]
(530)[2587]
(531)[2592]
(532)[2597]
(533)[2602]
(534)[2607]
(535)[2612]
(536)[2617]
(537)[2622]
(538)[2626]
(539)[2631]
(540)[2636]
(541)[2641]
(542)[2646]
(543)[2651]
(544)[2656]
(545)[2661]
(546)[2666]
(547)[2670]
(548)[2675]
(549)[2680]
(550)[2685]
(551)[2690]
(552)[2695]
(553)[2700]
(554)[2705]
(555)[2709]
(556)[2714]
(557)[2719]
(558)[2724]
(559)[2729]
(560)[2734]
(561)[2739]
(562)[2744]
(563)[2749]
(564)[2753]
(565)[2758]
(566)[2763]
(567)[2768]
(568)[2773]
(569)[2778]
(570)[2783]
(571)[2788]
(572)[2792]
(573)[2797]
(574)[2802]
(575)[2807]
(576)[2812]
(577)[2817]
(578)[2822]
(579)[2827]
(580)[2832]
(581)[2836]
(582)[2841]
(583)[2846]
(584)[2851]
(585)[2856]
(586)[2861]
(587)[2866]
(588)[2871]
(589)[2875]
(590)[2880]
(591)[2885]
(592)[2890]
(593)[2895]
(594)[2900]
(595)[2905]
(596)[2910]
(597)[2915]
(598)[2919]
(599)[2924]
(600)[2929]
(601)[2934]
(602)[2939]
(603)[2944]
(604)[2949]
(605)[2954]
(606)[2958]
(607)[2963]
(608)[2968]
(609)[2973]
(610)[2978]
(611)[2983]
(612)[2988]
(613)[2993]
(614)[2998]
(615)[3002]
(616)[3007]
(617)[3012]
(618)[3017]
(619)[3022]
(620)[3027]
(621)[3032]
(622)[3037]
(623)[3041]
(624)[3046]
(625)[3051]
(626)[3056]
(627)[3061]
(628)[3066]
(629)[3071]
(630)[3076]
(631)[3081]
(632)[3085]
(633)[3090]
(634)[3095]
(635)[3100]
(636)[3105]
(637)[3110]
(638)[3115]
(639)[3120]
(640)[3125]
(641)[3129]
(642)[3134]
(643)[3139]
(644)[3144]
(645)[3149]
(646)[3154]
(647)[3159]
(648)[3164]
(649)[3168]
(650)[3173]
(651)[3178]
(652)[3183]
(653)[3188]
(654)[3193]
(655)[3198]
(656)[3203]
(657)[3208]
(658)[3212]
(659)[3217]
(660)[3222]
(661)[3227]
(662)[3232]
(663)[3237]
(664)[3242]
(665)[3247]
(666)[3251]
(667)[3256]
(668)[3261]
(669)[3266]
(670)[3271]
(671)[3276]
(672)[3281]
(673)[3286]
(674)[3291]
(675)[3295]
(676)[3300]
(677)[3305]
(678)[3310]
(679)[3315]
(680)[3320]
(681)[3325]
(682)[3330]
(683)[3334]
(684)[3339]
(685)[3344]
(686)[3349]
(687)[3354]
(688)[3359]
(689)[3364]
(690)[3369]
(691)[3374]
(692)[3378]
(693)[3383]
(694)[3388]
(695)[3393]
(696)[3398]
(697)[3403]
(698)[3408]
(699)[3413]
(700)[3417]
(701)[3422]
(702)[3427]
(703)[3432]
(704)[3437]
(705)[3442]
(706)[3447]
(707)[3452]
(708)[3457]
(709)[3461]
(710)[3466]
(711)[3471]
(712)[3476]
(713)[3481]
(714)[3486]
(715)[3491]
(716)[3496]
(717)[3500]
(718)[3505]
(719)[3510]
(720)[3515]
(721)[3520]
(722)[3525]
(723)[3530]
(724)[3535]
(725)[3540]
(726)[3544]
(727)[3549]
(728)[3554]
(729)[3559]
(730)[3564]
(731)[3569]
(732)[3574]
(733)[3579]
(734)[3583]
(735)[3588]
(736)[3593]
(737)[3598]
(738)[3603]
(739)[3608]
(740)[3613]
(741)[3618]
(742)[3623]
(743)[3627]
(744)[3632]
(745)[3637]
(746)[3642]
(747)[3647]
(748)[3652]
(749)[3657]
(750)[3662]
(751)[3666]
(752)[3671]
(753)[3676]
(754)[3681]
(755)[3686]
(756)[3691]
(757)[3696]
(758)[3701]
(759)[3706]
(760)[3710]
(761)[3715]
(762)[3720]
(763)[3725]
(764)[3730]
(765)[3735]
(766)[3740]
(767)[3745]
(768)[3750]
(769)[3754]
(770)[3759]
(771)[3764]
(772)[3769]
(773)[3774]
(774)[3779]
(775)[3784]
(776)[3789]
(777)[3793]
(778)[3798]
(779)[3803]
(780)[3808]
(781)[3813]
(782)[3818]
(783)[3823]
(784)[3828]
(785)[3833]
(786)[3837]
(787)[3842]
(788)[3847]
(789)[3852]
(790)[3857]
(791)[3862]
(792)[3867]
(793)[3872]
(794)[3876]
(795)[3881]
(796)[3886]
(797)[3891]
(798)[3896]
(799)[3901]
(800)[3906]
(801)[3911]
(802)[3916]
(803)[3920]
(804)[3925]
(805)[3930]
(806)[3935]
(807)[3940]
(808)[3945]
(809)[3950]
(810)[3955]
(811)[3959]
(812)[3964]
(813)[3969]
(814)[3974]
(815)[3979]
(816)[3984]
(817)[3989]
(818)[3994]
(819)[3999]
(820)[4003]
(821)[4008]
(822)[4013]
(823)[4018]
(824)[4023]
(825)[4028]
(826)[4033]
(827)[4038]
(828)[4042]
(829)[4047]
(830)[4052]
(831)[4057]
(832)[4062]
(833)[4067]
(834)[4072]
(835)[4077]
(836)[4082]
(837)[4086]
(838)[4091]
(839)[4096]
(840)[4101]
(841)[4106]
(842)[4111]
(843)[4116]
(844)[4121]
(845)[4125]
(846)[4130]
(847)[4135]
(848)[4140]
(849)[4145]
(850)[4150]
(851)[4155]
(852)[4160]
(853)[4165]
(854)[4169]
(855)[4174]
(856)[4179]
(857)[4184]
(858)[4189]
(859)[4194]
(860)[4199]
(861)[4204]
(862)[4208]
(863)[4213]
(864)[4218]
(865)[4223]
(866)[4228]
(867)[4233]
(868)[4238]
(869)[4243]
(870)[4248]
(871)[4252]
(872)[4257]
(873)[4262]
(874)[4267]
(875)[4272]
(876)[4277]
(877)[4282]
(878)[4287]
(879)[4291]
(880)[4296]
(881)[4301]
(882)[4306]
(883)[4311]
(884)[4316]
(885)[4321]
(886)[4326]
(887)[4331]
(888)[4335]
(889)[4340]
(890)[4345]
(891)[4350]
(892)[4355]
(893)[4360]
(894)[4365]
(895)[4370]
(896)[4375]
(897)[4379]
(898)[4384]
(899)[4389]
(900)[4394]
(901)[4399]
(902)[4404]
(903)[4409]
(904)[4414]
(905)[4418]
(906)[4423]
(907)[4428]
(908)[4433]
(909)[4438]
(910)[4443]
(911)[4448]
(912)[4453]
(913)[4458]
(914)[4462]
(915)[4467]
(916)[4472]
(917)[4477]
(918)[4482]
(919)[4487]
(920)[4492]
(921)[4497]
(922)[4501]
(923)[4506]
(924)[4511]
(925)[4516]
(926)[4521]
(927)[4526]
(928)[4531]
(929)[4536]
(930)[4541]
(931)[4545]
(932)[4550]
(933)[4555]
(934)[4560]
(935)[4565]
(936)[4570]
(937)[4575]
(938)[4580]
(939)[4584]
(940)[4589]
(941)[4594]
(942)[4599]
(943)[4604]
(944)[4609]
(945)[4614]
(946)[4619]
(947)[4624]
(948)[4628]
(949)[4633]
(950)[4638]
(951)[4643]
(952)[4648]
(953)[4653]
(954)[4658]
(955)[4663]
(956)[4667]
(957)[4672]
(958)[4677]
(959)[4682]
(960)[4687]
(961)[4692]
(962)[4697]
(963)[4702]
(964)[4707]
(965)[4711]
(966)[4716]
(967)[4721]
(968)[4726]
(969)[4731]
(970)[4736]
(971)[4741]
(972)[4746]
(973)[4750]
(974)[4755]
(975)[4760]
(976)[4765]
(977)[4770]
(978)[4775]
(979)[4780]
(980)[4785]
(981)[4790]
(982)[4794]
(983)[4799]
(984)[4804]
(985)[4809]
(986)[4814]
(987)[4819]
(988)[4824]
(989)[4829]
(990)[4833]
(991)[4838]
(992)[4843]
(993)[4848]
(994)[4853]
(995)[4858]
(996)[4863]
(997)[4868]
(998)[4873]
(999)[4877]
(1000)[4882]
(1001)[4887]
(1002)[4892]
(1003)[4897]
(1004)[4902]
(1005)[4907]
(1006)[4912]
(1007)[4916]
(1008)[4921]
(1009)[4926]
(1010)[4931]
(1011)[4936]
(1012)[4941]
(1013)[4946]
(1014)[4951]
(1015)[4956]
(1016)[4960]
(1017)[4965]
(1018)[4970]
(1019)[4975]
(1020)[4980]
(1021)[4985]
(1022)[4990]
(1023)[4995]
(1024)[5000]


```