Hi, someone is helping me. It's a program that I wrote, and it's slower. The way is the program. If you can help me
word index = 0;
float D1=0;
float D2=0;
float D3=0;
float D4=0;
float D5=0;
.
.
.
float D100=0;
void setup() {
Serial.begin(9600);
}
void loop() {
index = index + 1;
delay(100);
if (index==1)){
D1= analogRead(A0)/23;
}
if (index==2)){
D2= analogRead(A0)/23;
}
if (index==3)){
D3= analogRead(A0)/23;
}
if (index==4)){
D4= analogRead(A0)/23;
}
if (index==5)){
D5= analogRead(A0)/23;
}
.
.
.
if (index==100)){
D100= analogRead(A0)/23;
}
if (index>100)){
Serial.println(D1);
Serial.println(D2);
Serial.println(D3);
Serial.println(D4);
.
.
.
Serial.println(D100);
}
}
system
November 19, 2018, 8:37pm
2
void loop() {
index = index + 1;
if (index==1)){
D1= analogRead(A0)/23;
}
You're welcome
What method should I use to reduce the size of the program?
system
November 19, 2018, 8:47pm
4
Smaller source, smaller compiled code or smaller RAM?
I do not want to lose much RAM. I want to reduce the length of the program. What loop should I use?
Your program uses a lot of float variables, which isn't necessary as analogRead() outputs an integer from 0-1023, so only 1024 possible values, and using division also is slow. Consider rewriting the math so you handle the read in a different way that keeps everything as integers until the final print formatting.
I want to reduce the number of program lines. What should I do?
system
November 19, 2018, 9:01pm
8
Use arrays and for loops.
Probably.
What should I do if I want to define at first the definition of D from 1 to 100 floats?