[Solved] I used == comparison instead of = to assign new values

I am using the map() function to convert analog signal to % humidity from soil moisture sensors. I want to track running min and max values, but when I compare the return of map() to my values it seems to not be working. I set the initial min to 101% and max to -1% so the first time it runs it should overwrite with any valid reading. (map is set with 0 and 100 as min and max).

Here is my code:

#define PIN_MOISTURE_1 28 // Define pin to read soil moisture sensor
#define PIN_MOISTURE_2 26
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  int moisture1Min = 101;
  int moisture1Max = -1;
  int moisture2Min = 101;
  int moisture2Max = -1;
  bool run = true; // Set var to have do loop run
  do{
    int sensor1 = analogRead(PIN_MOISTURE_1); // Read signal from ADC, inverse correlation between signal and moisture
    // May need to calibrate for each sensor (Find Min and Max and use math to normalize output)
    long moisture1 = map(sensor1, 0, 1024, 100, 0); //Attempting inverse map
    int sensor2 = analogRead(PIN_MOISTURE_2);
    long moisture2 = map(sensor2, 0, 1024, 100, 0);
    if (moisture1 < moisture1Min) {
      moisture1Min == moisture1;
    }
    if (moisture1 > moisture1Max) {
      moisture1Max == moisture1;
    }
    if (moisture2 < moisture2Min) {
      moisture2Min == moisture2;
    }
    if (moisture2 > moisture2Max) {
      moisture2Max == moisture2;
    } 
    Serial.println("Moisture 1: " + String(moisture1) + "%; Moisture1 Min: " + String(moisture1Min) + "%; Moisture 1 Max: " + String(moisture1Max) + "%");
    delay(1000);
    Serial.println("Moisture 2: " + String(moisture2) + "%; Moisture2 Min: " + String(moisture2Min) + "%; Moisture 2 Max: " + String(moisture2Max) + "%");
    delay(1000);
  }while(run);
}

And example outputs:

20:59:32.055 -> Moisture 1: 27%; Moisture1 Min: 101%; Moisture 1 Max: -1%
20:59:33.051 -> Moisture 2: 28%; Moisture2 Min: 101%; Moisture 2 Max: -1%
20:59:34.036 -> Moisture 1: 27%; Moisture1 Min: 101%; Moisture 1 Max: -1%
20:59:35.028 -> Moisture 2: 28%; Moisture2 Min: 101%; Moisture 2 Max: -1%
20:59:36.019 -> Moisture 1: 27%; Moisture1 Min: 101%; Moisture 1 Max: -1%
20:59:37.019 -> Moisture 2: 28%; Moisture2 Min: 101%; Moisture 2 Max: -1%

So I am unsure why the 101 and -1 values persist when moisture1 is both > moisture1Max value of -1 and < moisture1Min value of 101.

In lines like the above, use "=", the assignment operator, rather than "==", the logical comparison operator for equality.

Thank you for catching that. It's been a minute since I've done any programming and I messed that it. That fixed it for me.

for the beginning - avoid the copy/duplicate of lines of codes.
By using an array you can trim down the amount of lines of codes drastically.
When you have to change something you only need to change it once.
When you need more sensors, just adopt the pin defintions and max/min initial values.

Write code once, use it often.

just as an example:

/*
    https://forum.arduino.cc/t/return-of-map-not-cooperating-with-relational-operators/1347809
    2025-01-28 by noiasca
*/

const uint8_t moisturePin[] {28, 26};              // define the pins as an array
const size_t noOfPin = sizeof(moisturePin) /  sizeof(moisturePin[0]);  // let  the compiler count the number of fields in your array
int moistureMin[noOfPin] {101, 101};             // use the same amount of fields for min values
int moistureMax[noOfPin] {-1, -1};               // use the same amount of fields for max values

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  for (size_t i = 0; i < noOfPin; i++) {
    int sensor = analogRead(moisturePin[i]);     // Read signal from ADC, inverse correlation between signal and moisture
    int moisture = map(sensor, 0, 1024, 100, 0); //Attempting inverse map
    constrain (moisture, 0, 100);                // sanitze data https://docs.arduino.cc/language-reference/en/functions/math/constrain/
    if (moisture < moistureMin[i]) {
      moistureMin[i] = moisture;
    }
    if (moisture > moistureMax[i]) {
      moistureMax[i] = moisture;
    }
    Serial.print("Moisture "); Serial.print(i); Serial.print(": "); Serial.print(moisture); Serial.print( "% ");
    Serial.print("Moisture Min: "); Serial.print(moistureMin[i]); Serial.print( "% ");
    Serial.print("Moisture Max: "); Serial.print(moistureMax[i]); Serial.println( "%");
    delay(1000);
  }
}
//

Note that the maximum value of an analog read == 1023
so you might need to replace 1024

Just out of my curiosity:
If 1023 is the maximum count of the ADC (analogRead()), then 1024 is the Full Count of the ADC -- am I correct?

There are 1024 values, from 0 to 1023

if you do map(sensor, 0, 1024, 100, 0), the way the map function is written, you'll never get 0.

you can try this if you don't believe me

void setup() {
  Serial.begin(115200);
  for (int i = 0; i < 1024; i++) {
    Serial.print(i);    Serial.write('\t');    Serial.println(map(i, 0, 1024, 100, 0));
  }
}

void loop() {}

if you want the full range (0% to 100%) then @robtillaart is right, you need to write
map(sensor, 0, 1023, 100, 0)
but note that this is unbalanced as you have a range for each value expect for 0% (ie an input of 0 to 10 will lead to 0%, 11 to 20 to 1%, ... but only 1023 will lead to 0%)

so if you want a balanced output, the smart way — in my opinion — is to use

map(i, 0, 1024, 100, -1)

you never reach 1024, so you'll never get -1 and 0% gets a full interval.

➜ try

void setup() {
  Serial.begin(115200);
  for (int i = 0; i < 1024; i++) {
    Serial.print(i);
    Serial.write('\t');
    Serial.println(map(i, 0, 1024, 100, -1));
  }
}

void loop() {}

you'll get

0	100
1	100
2	100
3	100
4	100
5	100
6	100
7	100
8	100
9	100
10	100
11	99
12	99
13	99
14	99
15	99
16	99
17	99
18	99
19	99
20	99
21	98
22	98
23	98
24	98
25	98
26	98
27	98
28	98
29	98
30	98
31	97
32	97
33	97
34	97
35	97
36	97
37	97
38	97
39	97
40	97
41	96
42	96
43	96
44	96
45	96
46	96
47	96
48	96
49	96
50	96
51	95
52	95
53	95
54	95
55	95
56	95
57	95
58	95
59	95
60	95
61	94
62	94
63	94
64	94
65	94
66	94
67	94
68	94
69	94
70	94
71	93
72	93
73	93
74	93
75	93
76	93
77	93
78	93
79	93
80	93
81	93
82	92
83	92
84	92
85	92
86	92
87	92
88	92
89	92
90	92
91	92
92	91
93	91
94	91
95	91
96	91
97	91
98	91
99	91
100	91
101	91
102	90
103	90
104	90
105	90
106	90
107	90
108	90
109	90
110	90
111	90
112	89
113	89
114	89
115	89
116	89
117	89
118	89
119	89
120	89
121	89
122	88
123	88
124	88
125	88
126	88
127	88
128	88
129	88
130	88
131	88
132	87
133	87
134	87
135	87
136	87
137	87
138	87
139	87
140	87
141	87
142	86
143	86
144	86
145	86
146	86
147	86
148	86
149	86
150	86
151	86
152	86
153	85
154	85
155	85
156	85
157	85
158	85
159	85
160	85
161	85
162	85
163	84
164	84
165	84
166	84
167	84
168	84
169	84
170	84
171	84
172	84
173	83
174	83
175	83
176	83
177	83
178	83
179	83
180	83
181	83
182	83
183	82
184	82
185	82
186	82
187	82
188	82
189	82
190	82
191	82
192	82
193	81
194	81
195	81
196	81
197	81
198	81
199	81
200	81
201	81
202	81
203	80
204	80
205	80
206	80
207	80
208	80
209	80
210	80
211	80
212	80
213	79
214	79
215	79
216	79
217	79
218	79
219	79
220	79
221	79
222	79
223	79
224	78
225	78
226	78
227	78
228	78
229	78
230	78
231	78
232	78
233	78
234	77
235	77
236	77
237	77
238	77
239	77
240	77
241	77
242	77
243	77
244	76
245	76
246	76
247	76
248	76
249	76
250	76
251	76
252	76
253	76
254	75
255	75
256	75
257	75
258	75
259	75
260	75
261	75
262	75
263	75
264	74
265	74
266	74
267	74
268	74
269	74
270	74
271	74
272	74
273	74
274	73
275	73
276	73
277	73
278	73
279	73
280	73
281	73
282	73
283	73
284	72
285	72
286	72
287	72
288	72
289	72
290	72
291	72
292	72
293	72
294	72
295	71
296	71
297	71
298	71
299	71
300	71
301	71
302	71
303	71
304	71
305	70
306	70
307	70
308	70
309	70
310	70
311	70
312	70
313	70
314	70
315	69
316	69
317	69
318	69
319	69
320	69
321	69
322	69
323	69
324	69
325	68
326	68
327	68
328	68
329	68
330	68
331	68
332	68
333	68
334	68
335	67
336	67
337	67
338	67
339	67
340	67
341	67
342	67
343	67
344	67
345	66
346	66
347	66
348	66
349	66
350	66
351	66
352	66
353	66
354	66
355	65
356	65
357	65
358	65
359	65
360	65
361	65
362	65
363	65
364	65
365	64
366	64
367	64
368	64
369	64
370	64
371	64
372	64
373	64
374	64
375	64
376	63
377	63
378	63
379	63
380	63
381	63
382	63
383	63
384	63
385	63
386	62
387	62
388	62
389	62
390	62
391	62
392	62
393	62
394	62
395	62
396	61
397	61
398	61
399	61
400	61
401	61
402	61
403	61
404	61
405	61
406	60
407	60
408	60
409	60
410	60
411	60
412	60
413	60
414	60
415	60
416	59
417	59
418	59
419	59
420	59
421	59
422	59
423	59
424	59
425	59
426	58
427	58
428	58
429	58
430	58
431	58
432	58
433	58
434	58
435	58
436	57
437	57
438	57
439	57
440	57
441	57
442	57
443	57
444	57
445	57
446	57
447	56
448	56
449	56
450	56
451	56
452	56
453	56
454	56
455	56
456	56
457	55
458	55
459	55
460	55
461	55
462	55
463	55
464	55
465	55
466	55
467	54
468	54
469	54
470	54
471	54
472	54
473	54
474	54
475	54
476	54
477	53
478	53
479	53
480	53
481	53
482	53
483	53
484	53
485	53
486	53
487	52
488	52
489	52
490	52
491	52
492	52
493	52
494	52
495	52
496	52
497	51
498	51
499	51
500	51
501	51
502	51
503	51
504	51
505	51
506	51
507	50
508	50
509	50
510	50
511	50
512	50
513	50
514	50
515	50
516	50
517	50
518	49
519	49
520	49
521	49
522	49
523	49
524	49
525	49
526	49
527	49
528	48
529	48
530	48
531	48
532	48
533	48
534	48
535	48
536	48
537	48
538	47
539	47
540	47
541	47
542	47
543	47
544	47
545	47
546	47
547	47
548	46
549	46
550	46
551	46
552	46
553	46
554	46
555	46
556	46
557	46
558	45
559	45
560	45
561	45
562	45
563	45
564	45
565	45
566	45
567	45
568	44
569	44
570	44
571	44
572	44
573	44
574	44
575	44
576	44
577	44
578	43
579	43
580	43
581	43
582	43
583	43
584	43
585	43
586	43
587	43
588	43
589	42
590	42
591	42
592	42
593	42
594	42
595	42
596	42
597	42
598	42
599	41
600	41
601	41
602	41
603	41
604	41
605	41
606	41
607	41
608	41
609	40
610	40
611	40
612	40
613	40
614	40
615	40
616	40
617	40
618	40
619	39
620	39
621	39
622	39
623	39
624	39
625	39
626	39
627	39
628	39
629	38
630	38
631	38
632	38
633	38
634	38
635	38
636	38
637	38
638	38
639	37
640	37
641	37
642	37
643	37
644	37
645	37
646	37
647	37
648	37
649	36
650	36
651	36
652	36
653	36
654	36
655	36
656	36
657	36
658	36
659	36
660	35
661	35
662	35
663	35
664	35
665	35
666	35
667	35
668	35
669	35
670	34
671	34
672	34
673	34
674	34
675	34
676	34
677	34
678	34
679	34
680	33
681	33
682	33
683	33
684	33
685	33
686	33
687	33
688	33
689	33
690	32
691	32
692	32
693	32
694	32
695	32
696	32
697	32
698	32
699	32
700	31
701	31
702	31
703	31
704	31
705	31
706	31
707	31
708	31
709	31
710	30
711	30
712	30
713	30
714	30
715	30
716	30
717	30
718	30
719	30
720	29
721	29
722	29
723	29
724	29
725	29
726	29
727	29
728	29
729	29
730	28
731	28
732	28
733	28
734	28
735	28
736	28
737	28
738	28
739	28
740	28
741	27
742	27
743	27
744	27
745	27
746	27
747	27
748	27
749	27
750	27
751	26
752	26
753	26
754	26
755	26
756	26
757	26
758	26
759	26
760	26
761	25
762	25
763	25
764	25
765	25
766	25
767	25
768	25
769	25
770	25
771	24
772	24
773	24
774	24
775	24
776	24
777	24
778	24
779	24
780	24
781	23
782	23
783	23
784	23
785	23
786	23
787	23
788	23
789	23
790	23
791	22
792	22
793	22
794	22
795	22
796	22
797	22
798	22
799	22
800	22
801	21
802	21
803	21
804	21
805	21
806	21
807	21
808	21
809	21
810	21
811	21
812	20
813	20
814	20
815	20
816	20
817	20
818	20
819	20
820	20
821	20
822	19
823	19
824	19
825	19
826	19
827	19
828	19
829	19
830	19
831	19
832	18
833	18
834	18
835	18
836	18
837	18
838	18
839	18
840	18
841	18
842	17
843	17
844	17
845	17
846	17
847	17
848	17
849	17
850	17
851	17
852	16
853	16
854	16
855	16
856	16
857	16
858	16
859	16
860	16
861	16
862	15
863	15
864	15
865	15
866	15
867	15
868	15
869	15
870	15
871	15
872	14
873	14
874	14
875	14
876	14
877	14
878	14
879	14
880	14
881	14
882	14
883	13
884	13
885	13
886	13
887	13
888	13
889	13
890	13
891	13
892	13
893	12
894	12
895	12
896	12
897	12
898	12
899	12
900	12
901	12
902	12
903	11
904	11
905	11
906	11
907	11
908	11
909	11
910	11
911	11
912	11
913	10
914	10
915	10
916	10
917	10
918	10
919	10
920	10
921	10
922	10
923	9
924	9
925	9
926	9
927	9
928	9
929	9
930	9
931	9
932	9
933	8
934	8
935	8
936	8
937	8
938	8
939	8
940	8
941	8
942	8
943	7
944	7
945	7
946	7
947	7
948	7
949	7
950	7
951	7
952	7
953	7
954	6
955	6
956	6
957	6
958	6
959	6
960	6
961	6
962	6
963	6
964	5
965	5
966	5
967	5
968	5
969	5
970	5
971	5
972	5
973	5
974	4
975	4
976	4
977	4
978	4
979	4
980	4
981	4
982	4
983	4
984	3
985	3
986	3
987	3
988	3
989	3
990	3
991	3
992	3
993	3
994	2
995	2
996	2
997	2
998	2
999	2
1000	2
1001	2
1002	2
1003	2
1004	1
1005	1
1006	1
1007	1
1008	1
1009	1
1010	1
1011	1
1012	1
1013	1
1014	0
1015	0
1016	0
1017	0
1018	0
1019	0
1020	0
1021	0
1022	0
1023	0

as you are mapping 1024 value onto 101 values, some will get 10 values in the input interval and some will get 11.

3 Likes

indeed, as that way you use the internal truncating effect (rounding down) of integer math to your advantage.

That's the idea indeed :slight_smile:

Actually, my query was a very simple one -- can we say that ADC's Full Count is 1024 (1023 +1 = MAX Count + 1) similar to the Full Count of TCNT1 which is 65536 (65535 + 1 = MAX Count + Overflow)?

The adc on the UNO is sampled on a 10 bit value hence the 0-1023 range.

imho the division by 1024 is quite good.

For the current use case ( a single threshold at ADC=101) it even doesn't matter what one chooses.

Just as experiment, if the threshold were ADC = 214 - what system behavior would @mcunkelman expect?

void setup() {
  Serial.begin(115200);
  for (int i = 0; i < 1024; i++) {
    Serial.print(i);
    Serial.write('\t');

    Serial.print(map(i, 0, 1024, 100, 0));  // as written by TO

    Serial.write('\t');
    Serial.print(map(i, 0, 1023, 100, 0));   // by robtillaart

    Serial.write('\t');
    Serial.print(map(i, 0, 1024, 100, -1));  // by J-M-L

    Serial.println();
  }
}

void loop() {}
|0|100|100|100|
|---|---|---|---|
|1|100|100|100|
|2|100|100|100|
|3|100|100|100|
|4|100|100|100|
|5|100|100|100|
|6|100|100|100|
|7|100|100|100|
|8|100|100|100|
|9|100|100|100|
|10|100|100|100|
|11|99|99|99|
|12|99|99|99|
|13|99|99|99|
|14|99|99|99|
|15|99|99|99|
|16|99|99|99|
|17|99|99|99|
|18|99|99|99|
|19|99|99|99|
|20|99|99|99|
|21|98|98|98|
|22|98|98|98|
|23|98|98|98|
|24|98|98|98|
|25|98|98|98|
|26|98|98|98|
|27|98|98|98|
|28|98|98|98|
|29|98|98|98|
|30|98|98|98|
|31|97|97|97|
|32|97|97|97|
|33|97|97|97|
|34|97|97|97|
|35|97|97|97|
|36|97|97|97|
|37|97|97|97|
|38|97|97|97|
|39|97|97|97|
|40|97|97|97|
|41|96|96|96|
|42|96|96|96|
|43|96|96|96|
|44|96|96|96|
|45|96|96|96|
|46|96|96|96|
|47|96|96|96|
|48|96|96|96|
|49|96|96|96|
|50|96|96|96|
|51|96|96|95|
|52|95|95|95|
|53|95|95|95|
|54|95|95|95|
|55|95|95|95|
|56|95|95|95|
|57|95|95|95|
|58|95|95|95|
|59|95|95|95|
|60|95|95|95|
|61|95|95|94|
|62|94|94|94|
|63|94|94|94|
|64|94|94|94|
|65|94|94|94|
|66|94|94|94|
|67|94|94|94|
|68|94|94|94|
|69|94|94|94|
|70|94|94|94|
|71|94|94|93|
|72|93|93|93|
|73|93|93|93|
|74|93|93|93|
|75|93|93|93|
|76|93|93|93|
|77|93|93|93|
|78|93|93|93|
|79|93|93|93|
|80|93|93|93|
|81|93|93|93|
|82|92|92|92|
|83|92|92|92|
|84|92|92|92|
|85|92|92|92|
|86|92|92|92|
|87|92|92|92|
|88|92|92|92|
|89|92|92|92|
|90|92|92|92|
|91|92|92|92|
|92|92|92|91|
|93|91|91|91|
|94|91|91|91|
|95|91|91|91|
|96|91|91|91|
|97|91|91|91|
|98|91|91|91|
|99|91|91|91|
|100|91|91|91|
|101|91|91|91|
|102|91|91|90|
|103|90|90|90|
|104|90|90|90|
|105|90|90|90|
|106|90|90|90|
|107|90|90|90|
|108|90|90|90|
|109|90|90|90|
|110|90|90|90|
|111|90|90|90|
|112|90|90|89|
|113|89|89|89|
|114|89|89|89|
|115|89|89|89|
|116|89|89|89|
|117|89|89|89|
|118|89|89|89|
|119|89|89|89|
|120|89|89|89|
|121|89|89|89|
|122|89|89|88|
|123|88|88|88|
|124|88|88|88|
|125|88|88|88|
|126|88|88|88|
|127|88|88|88|
|128|88|88|88|
|129|88|88|88|
|130|88|88|88|
|131|88|88|88|
|132|88|88|87|
|133|88|87|87|
|134|87|87|87|
|135|87|87|87|
|136|87|87|87|
|137|87|87|87|
|138|87|87|87|
|139|87|87|87|
|140|87|87|87|
|141|87|87|87|
|142|87|87|86|
|143|87|87|86|
|144|86|86|86|
|145|86|86|86|
|146|86|86|86|
|147|86|86|86|
|148|86|86|86|
|149|86|86|86|
|150|86|86|86|
|151|86|86|86|
|152|86|86|86|
|153|86|86|85|
|154|85|85|85|
|155|85|85|85|
|156|85|85|85|
|157|85|85|85|
|158|85|85|85|
|159|85|85|85|
|160|85|85|85|
|161|85|85|85|
|162|85|85|85|
|163|85|85|84|
|164|84|84|84|
|165|84|84|84|
|166|84|84|84|
|167|84|84|84|
|168|84|84|84|
|169|84|84|84|
|170|84|84|84|
|171|84|84|84|
|172|84|84|84|
|173|84|84|83|
|174|84|83|83|
|175|83|83|83|
|176|83|83|83|
|177|83|83|83|
|178|83|83|83|
|179|83|83|83|
|180|83|83|83|
|181|83|83|83|
|182|83|83|83|
|183|83|83|82|
|184|83|83|82|
|185|82|82|82|
|186|82|82|82|
|187|82|82|82|
|188|82|82|82|
|189|82|82|82|
|190|82|82|82|
|191|82|82|82|
|192|82|82|82|
|193|82|82|81|
|194|82|82|81|
|195|81|81|81|
|196|81|81|81|
|197|81|81|81|
|198|81|81|81|
|199|81|81|81|
|200|81|81|81|
|201|81|81|81|
|202|81|81|81|
|203|81|81|80|
|204|81|81|80|
|205|80|80|80|
|206|80|80|80|
|207|80|80|80|
|208|80|80|80|
|209|80|80|80|
|210|80|80|80|
|211|80|80|80|
|212|80|80|80|
|213|80|80|79|
|214|80|80|79|
|215|80|79|79|
|216|79|79|79|
|217|79|79|79|
|218|79|79|79|
|219|79|79|79|
|220|79|79|79|
|221|79|79|79|
|222|79|79|79|
|223|79|79|79|
|224|79|79|78|
|225|79|79|78|
|226|78|78|78|
|227|78|78|78|
|228|78|78|78|
|229|78|78|78|
|230|78|78|78|
|231|78|78|78|
|232|78|78|78|
|233|78|78|78|
|234|78|78|77|
|235|78|78|77|
|236|77|77|77|
|237|77|77|77|
|238|77|77|77|
|239|77|77|77|
|240|77|77|77|
|241|77|77|77|
|242|77|77|77|
|243|77|77|77|
|244|77|77|76|
|245|77|77|76|
|246|76|76|76|
|247|76|76|76|
|248|76|76|76|
|249|76|76|76|
|250|76|76|76|
|251|76|76|76|
|252|76|76|76|
|253|76|76|76|
|254|76|76|75|
|255|76|76|75|
|256|75|75|75|
|257|75|75|75|
|258|75|75|75|
|259|75|75|75|
|260|75|75|75|
|261|75|75|75|
|262|75|75|75|
|263|75|75|75|
|264|75|75|74|
|265|75|75|74|
|266|75|74|74|
|267|74|74|74|
|268|74|74|74|
|269|74|74|74|
|270|74|74|74|
|271|74|74|74|
|272|74|74|74|
|273|74|74|74|
|274|74|74|73|
|275|74|74|73|
|276|74|74|73|
|277|73|73|73|
|278|73|73|73|
|279|73|73|73|
|280|73|73|73|
|281|73|73|73|
|282|73|73|73|
|283|73|73|73|
|284|73|73|72|
|285|73|73|72|
|286|73|73|72|
|287|72|72|72|
|288|72|72|72|
|289|72|72|72|
|290|72|72|72|
|291|72|72|72|
|292|72|72|72|
|293|72|72|72|
|294|72|72|72|
|295|72|72|71|
|296|72|72|71|
|297|71|71|71|
|298|71|71|71|
|299|71|71|71|
|300|71|71|71|
|301|71|71|71|
|302|71|71|71|
|303|71|71|71|
|304|71|71|71|
|305|71|71|70|
|306|71|71|70|
|307|71|70|70|
|308|70|70|70|
|309|70|70|70|
|310|70|70|70|
|311|70|70|70|
|312|70|70|70|
|313|70|70|70|
|314|70|70|70|
|315|70|70|69|
|316|70|70|69|
|317|70|70|69|
|318|69|69|69|
|319|69|69|69|
|320|69|69|69|
|321|69|69|69|
|322|69|69|69|
|323|69|69|69|
|324|69|69|69|
|325|69|69|68|
|326|69|69|68|
|327|69|69|68|
|328|68|68|68|
|329|68|68|68|
|330|68|68|68|
|331|68|68|68|
|332|68|68|68|
|333|68|68|68|
|334|68|68|68|
|335|68|68|67|
|336|68|68|67|
|337|68|68|67|
|338|67|67|67|
|339|67|67|67|
|340|67|67|67|
|341|67|67|67|
|342|67|67|67|
|343|67|67|67|
|344|67|67|67|
|345|67|67|66|
|346|67|67|66|
|347|67|67|66|
|348|67|66|66|
|349|66|66|66|
|350|66|66|66|
|351|66|66|66|
|352|66|66|66|
|353|66|66|66|
|354|66|66|66|
|355|66|66|65|
|356|66|66|65|
|357|66|66|65|
|358|66|66|65|
|359|65|65|65|
|360|65|65|65|
|361|65|65|65|
|362|65|65|65|
|363|65|65|65|
|364|65|65|65|
|365|65|65|64|
|366|65|65|64|
|367|65|65|64|
|368|65|65|64|
|369|64|64|64|
|370|64|64|64|
|371|64|64|64|
|372|64|64|64|
|373|64|64|64|
|374|64|64|64|
|375|64|64|64|
|376|64|64|63|
|377|64|64|63|
|378|64|64|63|
|379|63|63|63|
|380|63|63|63|
|381|63|63|63|
|382|63|63|63|
|383|63|63|63|
|384|63|63|63|
|385|63|63|63|
|386|63|63|62|
|387|63|63|62|
|388|63|63|62|
|389|63|62|62|
|390|62|62|62|
|391|62|62|62|
|392|62|62|62|
|393|62|62|62|
|394|62|62|62|
|395|62|62|62|
|396|62|62|61|
|397|62|62|61|
|398|62|62|61|
|399|62|61|61|
|400|61|61|61|
|401|61|61|61|
|402|61|61|61|
|403|61|61|61|
|404|61|61|61|
|405|61|61|61|
|406|61|61|60|
|407|61|61|60|
|408|61|61|60|
|409|61|61|60|
|410|60|60|60|
|411|60|60|60|
|412|60|60|60|
|413|60|60|60|
|414|60|60|60|
|415|60|60|60|
|416|60|60|59|
|417|60|60|59|
|418|60|60|59|
|419|60|60|59|
|420|59|59|59|
|421|59|59|59|
|422|59|59|59|
|423|59|59|59|
|424|59|59|59|
|425|59|59|59|
|426|59|59|58|
|427|59|59|58|
|428|59|59|58|
|429|59|59|58|
|430|59|58|58|
|431|58|58|58|
|432|58|58|58|
|433|58|58|58|
|434|58|58|58|
|435|58|58|58|
|436|58|58|57|
|437|58|58|57|
|438|58|58|57|
|439|58|58|57|
|440|58|57|57|
|441|57|57|57|
|442|57|57|57|
|443|57|57|57|
|444|57|57|57|
|445|57|57|57|
|446|57|57|57|
|447|57|57|56|
|448|57|57|56|
|449|57|57|56|
|450|57|57|56|
|451|56|56|56|
|452|56|56|56|
|453|56|56|56|
|454|56|56|56|
|455|56|56|56|
|456|56|56|56|
|457|56|56|55|
|458|56|56|55|
|459|56|56|55|
|460|56|56|55|
|461|55|55|55|
|462|55|55|55|
|463|55|55|55|
|464|55|55|55|
|465|55|55|55|
|466|55|55|55|
|467|55|55|54|
|468|55|55|54|
|469|55|55|54|
|470|55|55|54|
|471|55|54|54|
|472|54|54|54|
|473|54|54|54|
|474|54|54|54|
|475|54|54|54|
|476|54|54|54|
|477|54|54|53|
|478|54|54|53|
|479|54|54|53|
|480|54|54|53|
|481|54|53|53|
|482|53|53|53|
|483|53|53|53|
|484|53|53|53|
|485|53|53|53|
|486|53|53|53|
|487|53|53|52|
|488|53|53|52|
|489|53|53|52|
|490|53|53|52|
|491|53|53|52|
|492|52|52|52|
|493|52|52|52|
|494|52|52|52|
|495|52|52|52|
|496|52|52|52|
|497|52|52|51|
|498|52|52|51|
|499|52|52|51|
|500|52|52|51|
|501|52|52|51|
|502|51|51|51|
|503|51|51|51|
|504|51|51|51|
|505|51|51|51|
|506|51|51|51|
|507|51|51|50|
|508|51|51|50|
|509|51|51|50|
|510|51|51|50|
|511|51|51|50|
|512|50|50|50|
|513|50|50|50|
|514|50|50|50|
|515|50|50|50|
|516|50|50|50|
|517|50|50|50|
|518|50|50|49|
|519|50|50|49|
|520|50|50|49|
|521|50|50|49|
|522|50|49|49|
|523|49|49|49|
|524|49|49|49|
|525|49|49|49|
|526|49|49|49|
|527|49|49|49|
|528|49|49|48|
|529|49|49|48|
|530|49|49|48|
|531|49|49|48|
|532|49|48|48|
|533|48|48|48|
|534|48|48|48|
|535|48|48|48|
|536|48|48|48|
|537|48|48|48|
|538|48|48|47|
|539|48|48|47|
|540|48|48|47|
|541|48|48|47|
|542|48|48|47|
|543|47|47|47|
|544|47|47|47|
|545|47|47|47|
|546|47|47|47|
|547|47|47|47|
|548|47|47|46|
|549|47|47|46|
|550|47|47|46|
|551|47|47|46|
|552|47|47|46|
|553|46|46|46|
|554|46|46|46|
|555|46|46|46|
|556|46|46|46|
|557|46|46|46|
|558|46|46|45|
|559|46|46|45|
|560|46|46|45|
|561|46|46|45|
|562|46|46|45|
|563|46|45|45|
|564|45|45|45|
|565|45|45|45|
|566|45|45|45|
|567|45|45|45|
|568|45|45|44|
|569|45|45|44|
|570|45|45|44|
|571|45|45|44|
|572|45|45|44|
|573|45|44|44|
|574|44|44|44|
|575|44|44|44|
|576|44|44|44|
|577|44|44|44|
|578|44|44|43|
|579|44|44|43|
|580|44|44|43|
|581|44|44|43|
|582|44|44|43|
|583|44|44|43|
|584|43|43|43|
|585|43|43|43|
|586|43|43|43|
|587|43|43|43|
|588|43|43|43|
|589|43|43|42|
|590|43|43|42|
|591|43|43|42|
|592|43|43|42|
|593|43|43|42|
|594|42|42|42|
|595|42|42|42|
|596|42|42|42|
|597|42|42|42|
|598|42|42|42|
|599|42|42|41|
|600|42|42|41|
|601|42|42|41|
|602|42|42|41|
|603|42|42|41|
|604|42|41|41|
|605|41|41|41|
|606|41|41|41|
|607|41|41|41|
|608|41|41|41|
|609|41|41|40|
|610|41|41|40|
|611|41|41|40|
|612|41|41|40|
|613|41|41|40|
|614|41|40|40|
|615|40|40|40|
|616|40|40|40|
|617|40|40|40|
|618|40|40|40|
|619|40|40|39|
|620|40|40|39|
|621|40|40|39|
|622|40|40|39|
|623|40|40|39|
|624|40|40|39|
|625|39|39|39|
|626|39|39|39|
|627|39|39|39|
|628|39|39|39|
|629|39|39|38|
|630|39|39|38|
|631|39|39|38|
|632|39|39|38|
|633|39|39|38|
|634|39|39|38|
|635|38|38|38|
|636|38|38|38|
|637|38|38|38|
|638|38|38|38|
|639|38|38|37|
|640|38|38|37|
|641|38|38|37|
|642|38|38|37|
|643|38|38|37|
|644|38|38|37|
|645|38|37|37|
|646|37|37|37|
|647|37|37|37|
|648|37|37|37|
|649|37|37|36|
|650|37|37|36|
|651|37|37|36|
|652|37|37|36|
|653|37|37|36|
|654|37|37|36|
|655|37|36|36|
|656|36|36|36|
|657|36|36|36|
|658|36|36|36|
|659|36|36|36|
|660|36|36|35|
|661|36|36|35|
|662|36|36|35|
|663|36|36|35|
|664|36|36|35|
|665|36|35|35|
|666|35|35|35|
|667|35|35|35|
|668|35|35|35|
|669|35|35|35|
|670|35|35|34|
|671|35|35|34|
|672|35|35|34|
|673|35|35|34|
|674|35|35|34|
|675|35|35|34|
|676|34|34|34|
|677|34|34|34|
|678|34|34|34|
|679|34|34|34|
|680|34|34|33|
|681|34|34|33|
|682|34|34|33|
|683|34|34|33|
|684|34|34|33|
|685|34|34|33|
|686|34|33|33|
|687|33|33|33|
|688|33|33|33|
|689|33|33|33|
|690|33|33|32|
|691|33|33|32|
|692|33|33|32|
|693|33|33|32|
|694|33|33|32|
|695|33|33|32|
|696|33|32|32|
|697|32|32|32|
|698|32|32|32|
|699|32|32|32|
|700|32|32|31|
|701|32|32|31|
|702|32|32|31|
|703|32|32|31|
|704|32|32|31|
|705|32|32|31|
|706|32|31|31|
|707|31|31|31|
|708|31|31|31|
|709|31|31|31|
|710|31|31|30|
|711|31|31|30|
|712|31|31|30|
|713|31|31|30|
|714|31|31|30|
|715|31|31|30|
|716|31|31|30|
|717|30|30|30|
|718|30|30|30|
|719|30|30|30|
|720|30|30|29|
|721|30|30|29|
|722|30|30|29|
|723|30|30|29|
|724|30|30|29|
|725|30|30|29|
|726|30|30|29|
|727|30|29|29|
|728|29|29|29|
|729|29|29|29|
|730|29|29|28|
|731|29|29|28|
|732|29|29|28|
|733|29|29|28|
|734|29|29|28|
|735|29|29|28|
|736|29|29|28|
|737|29|28|28|
|738|28|28|28|
|739|28|28|28|
|740|28|28|28|
|741|28|28|27|
|742|28|28|27|
|743|28|28|27|
|744|28|28|27|
|745|28|28|27|
|746|28|28|27|
|747|28|27|27|
|748|27|27|27|
|749|27|27|27|
|750|27|27|27|
|751|27|27|26|
|752|27|27|26|
|753|27|27|26|
|754|27|27|26|
|755|27|27|26|
|756|27|27|26|
|757|27|27|26|
|758|26|26|26|
|759|26|26|26|
|760|26|26|26|
|761|26|26|25|
|762|26|26|25|
|763|26|26|25|
|764|26|26|25|
|765|26|26|25|
|766|26|26|25|
|767|26|26|25|
|768|25|25|25|
|769|25|25|25|
|770|25|25|25|
|771|25|25|24|
|772|25|25|24|
|773|25|25|24|
|774|25|25|24|
|775|25|25|24|
|776|25|25|24|
|777|25|25|24|
|778|25|24|24|
|779|24|24|24|
|780|24|24|24|
|781|24|24|23|
|782|24|24|23|
|783|24|24|23|
|784|24|24|23|
|785|24|24|23|
|786|24|24|23|
|787|24|24|23|
|788|24|23|23|
|789|23|23|23|
|790|23|23|23|
|791|23|23|22|
|792|23|23|22|
|793|23|23|22|
|794|23|23|22|
|795|23|23|22|
|796|23|23|22|
|797|23|23|22|
|798|23|22|22|
|799|22|22|22|
|800|22|22|22|
|801|22|22|21|
|802|22|22|21|
|803|22|22|21|
|804|22|22|21|
|805|22|22|21|
|806|22|22|21|
|807|22|22|21|
|808|22|22|21|
|809|21|21|21|
|810|21|21|21|
|811|21|21|21|
|812|21|21|20|
|813|21|21|20|
|814|21|21|20|
|815|21|21|20|
|816|21|21|20|
|817|21|21|20|
|818|21|21|20|
|819|21|20|20|
|820|20|20|20|
|821|20|20|20|
|822|20|20|19|
|823|20|20|19|
|824|20|20|19|
|825|20|20|19|
|826|20|20|19|
|827|20|20|19|
|828|20|20|19|
|829|20|19|19|
|830|19|19|19|
|831|19|19|19|
|832|19|19|18|
|833|19|19|18|
|834|19|19|18|
|835|19|19|18|
|836|19|19|18|
|837|19|19|18|
|838|19|19|18|
|839|19|18|18|
|840|18|18|18|
|841|18|18|18|
|842|18|18|17|
|843|18|18|17|
|844|18|18|17|
|845|18|18|17|
|846|18|18|17|
|847|18|18|17|
|848|18|18|17|
|849|18|18|17|
|850|17|17|17|
|851|17|17|17|
|852|17|17|16|
|853|17|17|16|
|854|17|17|16|
|855|17|17|16|
|856|17|17|16|
|857|17|17|16|
|858|17|17|16|
|859|17|17|16|
|860|17|16|16|
|861|16|16|16|
|862|16|16|15|
|863|16|16|15|
|864|16|16|15|
|865|16|16|15|
|866|16|16|15|
|867|16|16|15|
|868|16|16|15|
|869|16|16|15|
|870|16|15|15|
|871|15|15|15|
|872|15|15|14|
|873|15|15|14|
|874|15|15|14|
|875|15|15|14|
|876|15|15|14|
|877|15|15|14|
|878|15|15|14|
|879|15|15|14|
|880|15|14|14|
|881|14|14|14|
|882|14|14|14|
|883|14|14|13|
|884|14|14|13|
|885|14|14|13|
|886|14|14|13|
|887|14|14|13|
|888|14|14|13|
|889|14|14|13|
|890|14|14|13|
|891|13|13|13|
|892|13|13|13|
|893|13|13|12|
|894|13|13|12|
|895|13|13|12|
|896|13|13|12|
|897|13|13|12|
|898|13|13|12|
|899|13|13|12|
|900|13|13|12|
|901|13|12|12|
|902|12|12|12|
|903|12|12|11|
|904|12|12|11|
|905|12|12|11|
|906|12|12|11|
|907|12|12|11|
|908|12|12|11|
|909|12|12|11|
|910|12|12|11|
|911|12|11|11|
|912|11|11|11|
|913|11|11|10|
|914|11|11|10|
|915|11|11|10|
|916|11|11|10|
|917|11|11|10|
|918|11|11|10|
|919|11|11|10|
|920|11|11|10|
|921|11|10|10|
|922|10|10|10|
|923|10|10|9|
|924|10|10|9|
|925|10|10|9|
|926|10|10|9|
|927|10|10|9|
|928|10|10|9|
|929|10|10|9|
|930|10|10|9|
|931|10|9|9|
|932|9|9|9|
|933|9|9|8|
|934|9|9|8|
|935|9|9|8|
|936|9|9|8|
|937|9|9|8|
|938|9|9|8|
|939|9|9|8|
|940|9|9|8|
|941|9|9|8|
|942|9|8|8|
|943|8|8|7|
|944|8|8|7|
|945|8|8|7|
|946|8|8|7|
|947|8|8|7|
|948|8|8|7|
|949|8|8|7|
|950|8|8|7|
|951|8|8|7|
|952|8|7|7|
|953|7|7|7|
|954|7|7|6|
|955|7|7|6|
|956|7|7|6|
|957|7|7|6|
|958|7|7|6|
|959|7|7|6|
|960|7|7|6|
|961|7|7|6|
|962|7|6|6|
|963|6|6|6|
|964|6|6|5|
|965|6|6|5|
|966|6|6|5|
|967|6|6|5|
|968|6|6|5|
|969|6|6|5|
|970|6|6|5|
|971|6|6|5|
|972|6|5|5|
|973|5|5|5|
|974|5|5|4|
|975|5|5|4|
|976|5|5|4|
|977|5|5|4|
|978|5|5|4|
|979|5|5|4|
|980|5|5|4|
|981|5|5|4|
|982|5|5|4|
|983|5|4|4|
|984|4|4|3|
|985|4|4|3|
|986|4|4|3|
|987|4|4|3|
|988|4|4|3|
|989|4|4|3|
|990|4|4|3|
|991|4|4|3|
|992|4|4|3|
|993|4|3|3|
|994|3|3|2|
|995|3|3|2|
|996|3|3|2|
|997|3|3|2|
|998|3|3|2|
|999|3|3|2|
|1000|3|3|2|
|1001|3|3|2|
|1002|3|3|2|
|1003|3|2|2|
|1004|2|2|1|
|1005|2|2|1|
|1006|2|2|1|
|1007|2|2|1|
|1008|2|2|1|
|1009|2|2|1|
|1010|2|2|1|
|1011|2|2|1|
|1012|2|2|1|
|1013|2|1|1|
|1014|1|1|0|
|1015|1|1|0|
|1016|1|1|0|
|1017|1|1|0|
|1018|1|1|0|
|1019|1|1|0|
|1020|1|1|0|
|1021|1|1|0|
|1022|1|1|0|
|1023|1|0|0|

OK, if you are happy with it feel free to use it :slight_smile:

Setting the maximum input higher than the actual maximum will result in the lower maximum reading (1023 or 1024) being mapped lower. Replace 1023 with 5000 to see the effect (output diminished by 4/5 of maximum output)

Sounds like you are sticking with 1023.

IDK if this is legit or not, good thing it really makes no difference unless you are wrangling with the unfortunate function which is map().

a7

Seldom use the map function macro for integers because of some side effects.

.

1 Like

Word. I use map() when I'm lazy and don't care about its flaws. I write code when things really matter, but I will bet my goto should be your functions.

Then my natural laziness will not be disturbed by needing to care about the flaws.

a7

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.