Hello all! I've got a question that's probably pretty stupid (especially since I've been doing basic Arduino stuff for a while) but I've never messed with things like arrays and For loops.
Basic summary of goals: I am going to have 8 pins pulled high with the internal pullups and always pulled low externally. I want to read when they go high, then send the value of which pin is high over an NRF24L01 to another Arduino.
Only one pin will ever go high at a time.
Problem: in the Void Loop, inside the If statement, I get the compiler error that "Box" was not declared in this scope.
What am I doing wrong here guys?
const int Box0 = 2; //Lid
const int Box1 = 3; //
const int Box2 = 4; //
const int Box3 = 5; //
const int Box4 = 6; //
const int Box5 = 9; //
const int Box6 = 10; //
const int Box7 = A0; //Bottom
int Signal;
/*
Pin 7 - CE
Pin 8 - CSN
Pin 11 - MOSI
Pin 12 - MISO
Pin 13 - SCK
*/
void setup(){
for(int i=0; i<=7; i++){
pinMode(Box[i], INPUT_PULLUP);
}
}
void loop(){
for(int i=0; i<=7; i++){
if(digitalRead(Box[i]) == HIGH){
Signal = i+1
}
else() Signal = 0;
}
}
RayLivingston:
Where do YOU see an array named "Box"? I see a bunch of int variables named Box0 through Box7, but no array anywhere...
Regards,
Ray L.
I think that's my problem, I haven't used an array because the pin numbers don't go directly in order. Can I name them Box0-Box7 but assign them to the random pins I have available?
Awesome. Thank you both for putting up with my admittedly noob question!
The end project is a gag gift that needs to play little music files from a separate box. I'll be sure to post it in the Exhibition section when it's done. Thanks again for the help!