Really basic question: in the following lines, what is being indicated by "sizeof (int)"?
The Sketch:
` const int VOL = A0; // Volume Pot pin
const int HALLPIN1 = A1; // hall effect analog sensor pins 1-5
const int HALLPIN2 = A2;
const int HALLPIN3 = A3;
const int HALLPIN4 = A4;
const int HALLPIN5 = A5;
const int leds[4] = {5,6,10,11};
void setup() {
pinMode(A0, INPUT); //volume
pinMode(A1, INPUT_PULLUP); //analog Ch 1
pinMode(A2, INPUT_PULLUP); //analog Ch 2
pinMode(A3, INPUT_PULLUP); //analog Ch 3
pinMode(A4, INPUT); //analog Ch 4
pinMode(A5, INPUT); //analog Ch 5
for (int jj; jj<sizeof(leds)/sizeof(int);jj++) // this sets individual LEDs for randFlash
{
pinMode(leds[jj],OUTPUT);
delay(9);
}
}
void randFlash()
{
digitalWrite(leds[random(0,sizeof(leds)/sizeof(int))],HIGH);
delay(random(4,57));
digitalWrite(leds[random(0,sizeof(leds)/sizeof(int))],LOW);
}
void noFlash()
{
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
}
void ledOff()
{
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
}
void loop() {
int volPotVal = analogRead(VOL);
int sens1Val = analogRead(HALLPIN1);
int sens2Val = analogRead(HALLPIN2);
int sens3Val = analogRead(HALLPIN3);
int sens4Val = analogRead(HALLPIN4);
int sens5Val = analogRead(HALLPIN5);
if ((sens1Val < 400) // Tests if any hall sensor value is under 400
|| (sens2Val < 400)
|| (sens3Val < 400)
|| (sens4Val < 400)
|| (sens5Val < 400))
{randFlash(); // randomly flashes LEDS
}
else {noFlash(); // LEDs solidly lit
}
}
`
These bits of code work, and I'm trying to parse it out. I understand MOST of what's happening here, but I don't know how sizeof(leds)/sizeof(int) works.
sizeof(leds) returns a value of 4, right? The 4 leds in my array? is it right that 4 is being divided by whatever the value of sizeof(int) is?
I'm in the Getting Started with Sketches book, but I haven't seen how this works based on the examples given therein. Can someone help me parse this so I can move on?
Thanks...
