Compiler is giving me a " 'delayPeriod' was not declared in this scope" error message. I thought I was supposed to initialize variables, esp. constants, in the setup section. I feel like I missing something huge here.
=====================
void setup() {
// Define input pins
const int lhInput = 1;
const int rhInput = 2;
// Turn all 7-seg display7 to output
for(int i = 4; i <= 12; i++){
pinMode(i, OUTPUT);
}
In C variables are only valid in the scope they were declared in. Have a look at the example and play with it a bit. Print the values, so you can understand the differences.
int globalVariable = 0;
void setup()
{
int localVariable1 = 0;
localVariable1++; // this is valid
localVariable2++; // this is not valid
globalVariable++; // this is valid too
for(int i = 0; i <= pulses; i++)
{
// i is only valid inside the for loop
}
i++; // not valid, i no longer exists
}
void loop()
{
int localVariable2 = 0;
static int staticVariable = 0;
localVariable1++; // this is not valid
localVariable2++; // this is valid, but variable will be deleted every time loop finishes
globalVariable++; // this is valid too
staticVariable++; // this is valid, but variable keeps value from loop to loop
}
The setup function is for code you only want to run once at the beginning.
The loop is called over and over again.
They are still simple C functions and variables/objects you need in both need to be global.
Had a feeling it was something that basic. It could've been really easy to be snarky about it, but you guys offered something constructive. Really appreciate it. Nice community.