Creating an array of variable names
hi,
i trying create array out of these names, possible?
deviceaddress part of dallastemperature library
thanks,
thorin
i trying create array out of these names, possible?
deviceaddress part of dallastemperature library
code: [select]
deviceaddress black = {0x28, 0xff, 0x1a, 0xaa, 0x62, 0x15, 0x03, 0x20};
deviceaddress red = {0x28, 0xff, 0xa9, 0xb4, 0x62, 0x15, 0x03, 0x0c};
deviceaddress green = {0x28, 0xff, 0xf5, 0xb3, 0x62, 0x15, 0x03, 0x3e};
how make work?
deviceaddress devices[] = {black, red, green};
so can use;
for(deviceaddress device : devices) {
sensors.setresolution(device, 10);
}
thanks,
thorin
you can't put variable names in array because names used compiler , not exist in code uploaded arduino.
you can create array of pointers, may little complex if beginner.
a simpler way make array holds addresses - like
(hope have syntax correct - not quite, see reply #2)
and can refer them deviceaddresss[0] or [1] etc.
you have
and refer addresses deviceaddresses[red]; etc
...r
you can create array of pointers, may little complex if beginner.
a simpler way make array holds addresses - like
code: [select]
byte deviceaddresses[3][] = {
{0x28, 0xff, 0x1a, 0xaa, 0x62, 0x15, 0x03, 0x20}.
{0x28, 0xff, 0xa9, 0xb4, 0x62, 0x15, 0x03, 0x0c}.
{0x28, 0xff, 0xf5, 0xb3, 0x62, 0x15, 0x03, 0x3e}
}
(hope have syntax correct - not quite, see reply #2)
and can refer them deviceaddresss[0] or [1] etc.
you have
code: [select]
#define black 0
#define red 1
#define green 2
and refer addresses deviceaddresses[red]; etc
...r
Arduino Forum > Using Arduino > Programming Questions > Creating an array of variable names
arduino
Comments
Post a Comment