Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // based on the examples from:
- // https://www.geeksforgeeks.org/pointer-array-array-pointer/
- // Read the explanation and then search for "C program to print elements of a 2-D array"
- int Red1;
- int Green1;
- int Blue1;
- // You need to fix your dimensions. You have them backward in your code
- int zombies[6][3] = {
- {101, 52, 150},
- {123, 82, 174},
- {116, 182, 82},
- {148, 199, 115},
- {86, 148, 30},
- {71, 24, 113}
- };
- int sunset[6][3] = {
- {250, 162, 117},
- {255, 140, 97},
- {206, 106, 133},
- {152, 82, 119},
- {92, 55, 76},
- {92, 55, 76}
- };
- void setup() {
- // put your setup code here, to run once:
- Serial.begin(9600);
- // a variable to select which array to load
- byte array_select = 0;
- // create a pointer variable to the inner-dimension
- int (*array_ptr)[3];
- // select which array to load
- if (array_select == 0)
- // point the pointer to the array
- array_ptr = zombies;
- if (array_select == 1)
- array_ptr = sunset;
- // load the values from the array
- Red1 = array_ptr[0][0];
- Green1 = array_ptr[0][1];
- Blue1 = array_ptr[0][2];
- Serial.println(F("---"));
- Serial.println(Red1);
- Serial.println(Green1);
- Serial.println(Blue1);
- }
- void loop() {
- // put your main code here, to run repeatedly:
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement