'How to create a three-by-three floating array in Arduino
I need a three-by-three array of flutes that should be in a loop (the loop can be used and should be displayed at the terminal output) I found the following code on the internet but it only prints one type of one-dimensional floating data
template<class T> inline Print &operator <<(Print &obj, T arg) { obj.print(arg); return obj; }
void setup() {
Serial.begin(9600);
}
void loop() {
int name = 1;
int age = 3;
Serial << "My name is " << name << " and I am " << age << " years old.";
Serial.println();
delay(500);
String bob1 = "bob";
Serial.println(bob1);
delay(500);
float f1 = 1.31;
float f2 = 2.39;
float f3 = 3.01;
float arr[3] = { f1, f2, f3 };
Serial << f1 << " " << f2 << " " << f3;
Serial.println();
}
Solution 1:[1]
Below solution solved my problem
float ar[3][3][3] = {
{{5.6,1.7,2.6},// row 0
{3.4,9.9,2.2},
{8.3,3.7,3.2}},
{{2.9,4.6,4.6},
{2.5,4.5,4.2},
{15,16,17}},
{{8.7,8.9,5.7},
{8.5,9.7,4.5},
{4.7,2.8,9.7}}
};
void setup() {
Serial.begin(9600);
}
void loop()
for (int i=0;i<3;i++){
for (int j=0;j<3;j++){
for(int k=0;k<3;k++){
Serial.println(ar[i][j][k]);
delay(500);
}
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mansur Ul Hasan |
