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 <= 0.3) {Voltage = 0.3;}
if (Voltage >= 1.4 && Voltage <= 5.0) {Voltage = 1.4;}
ir_length = 1.0/ ( 0.0125 + ( ( Voltage - 0.4) * (0.0375/0.9) ) );
//Serial.println(sensorValue);
Serial.print("40");
Serial.print(",");
Serial.print( Voltage*100);
Serial.print(",");
Serial.print("20");
Serial.print(",");
Serial.print( ir_length );
Serial.print(",");
Serial.print("80");
Serial.print(",");
Serial.println("130");
delay(10);
}
配列化
#include <stdio.h>
int main(void){
int ii;
int s;
unsigned char qq[]={
80,78,77,76,75,75,74,73,72,71,
70,69,68,68,67,66,65,65,64,63,
63,62,61,61,60,60,59,58,58,57,
57,56,56,55,55,54,54,53,53,52,
52,51,51,50,50,50,49,49,48,48,
47,47,47,46,46,46,45,45,45,44,
44,44,43,43,43,42,42,42,41,41,
41,41,40,40,40,40,39,39,39,38,
38,38,38,37,37,37,37,37,36,36,
36,36,35,35,35,35,35,34,34,34,
34,34,33,33,33,33,33,32,32,32,
32,32,32,31,31,31,31,31,31,30,
30,30,30,30,30,30,29,29,29,29,
29,29,28,28,28,28,28,28,28,28,
27,27,27,27,27,27,27,27,26,26,
26,26,26,26,26,26,25,25,25,25,
25,25,25,25,25,25,24,24,24,24,
24,24,24,24,24,24,23,23,23,23,
23,23,23,23,23,23,22,22,22,22,
22,22,22,22,22,22,22,22,21,21,
21,21,21,21,21,21,21,21,21,21,
21,20,20,20,20,20,20,20,20,20,
20,20,20,20,20,20
};
for(ii = 400;ii <= 1300;ii=ii+4) {
s=(ii-400)>>2;
printf("%d \t %d \n",ii,qq[s]);
}//ii
}//main
400 80
404 78
408 77
412 76
416 75
420 75
424 74
428 73
432 72
436 71
440 70
444 69
448 68
452 68
456 67
460 66
464 65
468 65
472 64
476 63
480 63
484 62
488 61
492 61
496 60
500 60
504 59
508 58
512 58
516 57
520 57
524 56
528 56
532 55
536 55
540 54
544 54
548 53
552 53
556 52
560 52
564 51
568 51
572 50
576 50
580 50
584 49
588 49
592 48
596 48
600 47
604 47
608 47
612 46
616 46
620 46
624 45
628 45
632 45
636 44
640 44
644 44
648 43
652 43
656 43
660 42
664 42
668 42
672 41
676 41
680 41
684 41
688 40
692 40
696 40
700 40
704 39
708 39
712 39
716 38
720 38
724 38
728 38
732 37
736 37
740 37
744 37
748 37
752 36
756 36
760 36
764 36
768 35
772 35
776 35
780 35
784 35
788 34
792 34
796 34
800 34
804 34
808 33
812 33
816 33
820 33
824 33
828 32
832 32
836 32
840 32
844 32
848 32
852 31
856 31
860 31
864 31
868 31
872 31
876 30
880 30
884 30
888 30
892 30
896 30
900 30
904 29
908 29
912 29
916 29
920 29
924 29
928 28
932 28
936 28
940 28
944 28
948 28
952 28
956 28
960 27
964 27
968 27
972 27
976 27
980 27
984 27
988 27
992 26
996 26
1000 26
1004 26
1008 26
1012 26
1016 26
1020 26
1024 25
1028 25
1032 25
1036 25
1040 25
1044 25
1048 25
1052 25
1056 25
1060 25
1064 24
1068 24
1072 24
1076 24
1080 24
1084 24
1088 24
1092 24
1096 24
1100 24
1104 23
1108 23
1112 23
1116 23
1120 23
1124 23
1128 23
1132 23
1136 23
1140 23
1144 22
1148 22
1152 22
1156 22
1160 22
1164 22
1168 22
1172 22
1176 22
1180 22
1184 22
1188 22
1192 21
1196 21
1200 21
1204 21
1208 21
1212 21
1216 21
1220 21
1224 21
1228 21
1232 21
1236 21
1240 21
1244 20
1248 20
1252 20
1256 20
1260 20
1264 20
1268 20
1272 20
1276 20
1280 20
1284 20
1288 20
1292 20
1296 20
1300 20