I ran into a very odd issue while programming today...
The program has quite a few variables, some arrays, and booleans declared before setup().
In a function a boolean kept resetting once the function was exited, even though it had been declared in the first section of the listing!
Oddly enough another boolean declared immediately after the first worked fine.
As an experiment, I moved the boolean declarations up near the top of the declarations, but not right at the top. Suddenly it started working! I have never heard of this before, and didn't know the order of declaration was important. I moved all of the booleans up into the same area.
Has anyone else run into this issue?
Here's the listing, after the fix, up to setup()
boolean RPplayFlag=false; (third clump) was the problem child..
#include <SPI.h>
#include <avr/pgmspace.h>
#include <Wire.h>
#include <EEPROM.h>
//#include <avr/io.h>//??
//********temp buffers********
int tempInt=0;
byte temp1=0;
byte temp2=0;
byte tempArray[96];//used for core ram write(command 0x9c), and possibly other functions
int tempTemp=0;
byte ditherTime;
byte tempDith=0;
//*******timer buffers********
unsigned long milliTimer=0;
unsigned long milliTimerLast=0;
unsigned long microsDither=0;
unsigned long ledTimer=1500;//hold off on LEDs until power stable
unsigned long ledOffTimer=1500;
unsigned long microTimer=0;
unsigned long butTmr=1000;
unsigned long tempTester=3000;
unsigned long oneThird=0;
boolean microRolledArm=false;
boolean microRolledFlag=false;
//Control Flags *PUTTING ALL BOOLS HERE!!!
boolean RPplayFlag=false;
boolean RPrecFlag=false;
boolean splashOn = true;
boolean but=true;
boolean recButLast=true;
boolean recButMask=false;
boolean playButLast=true;
boolean playButMask=false;
boolean sliceButLast=true;
boolean sliceButMask=false;
boolean eqButLast=true;
boolean eqButMask=false;
//********PIN DEFINES**********
//RGB
const int eqR=11;
const int eqG=13;
const int eqB=12;
const int slaveSelectPin=53;
const int analogOutRed = 2;
const int analogOutBlue = 3;
const int analogOutGreen = 4;
const int tdaSwitch = 30;
const int sliceTG=5;//temporary, PWM
const int slicePlayTG=6;//temporary, PWM
const int playTG=7;//temporary, PWM
const int playST=8;//temporary, PWM //S-Trigger pullup (active High)
const int recTG=9;//temporary, PWM
const int recST=10;//temporary, PWM //S-Trigger pullup (active High)
//buttons (may change) pins 44-34
const int recBut=43;
const int playBut=48;
const int sliceBut=44;
const int eqBut=9; //A PWM PIN
const int modeBut=42;
const int playSelBut=49;
const int recTgBut=8;
const int playTgBut=47;
const int LoopBut=46;
//const int pLoopBut=43;
const int sliceSelBut=45;
byte butScan=0;
//LEDs (may change) pins 22-29 (8 rows)=PORTA0-7 for fast access and pins 30-33 (4 commons)=PORTC7-4
const int led0 = 22;//"rows" (ANODES) Each has resistor
const int led1 = 23;
const int led2 = 24;
const int led3 = 25;
const int led4 = 26;
const int led5 = 27;
const int led6 = 28;
const int led7 = 29;//<<These to here are not necessary, remove if need more RAM
const int ledD = 37; //"commons" (CATHODES)
const int ledC = 36;
const int ledB = 35;
const int ledA = 34; //port c,3 led circle
const int specClk=10;
//LEDs Defined as bits in these 4 bytes
byte ledBuf0=B11111111;
byte ledBuf1=B11111111;
byte ledBuf2=B11111111;
byte ledBuf3=B11111111;
byte ledScan=0;
byte dimmer=0;
int splashStep=0;
//****** BUTTON DEBOUNCE ******
byte recButDB=0;
byte playButDB=0;
byte sliceButDB=0;
byte eqButDB=0;
byte modeButDB=0;
byte playSelButDB=0;
byte recTgButDB=0;
byte playTgButDB=0;
byte LoopButDB=0;
byte sliceSelButDB=0;
int butHold=0;
//********ADC DEFINES**********
const int ratePot=A11;//0-5V, but zeroed at 2.5V: (RateCV-512)+(ratePot-512)
const int rateCV=A2;//zeroed at 2.5V
const int sgpPotCV=A5;//Start/Gmove/Position pot & CV; 0-5V
const int esPotCV=A4;//End/Size pot & CV ; 0-5V
const int eqPotCV=A1;//zeroed at 2.5V,512
const int peakADC=A0;
const int sliceCV=A6;
const int blendPot=A8;
const int feedBackPot=A7;//also offset with Expansion Module
const int specPin=A3;
const int startPot=A10;
const int endPot=A9;
int ratePotVal=0;
int startPotVal=0;
int endPotVal=0;
int fbkPotVal=0;
int blendPotVal=0;
byte potCnt=0;
// ******** TDA MOD FINISHED *******
byte tdaR[] = {//tda RP ini data
0x20,0x00,0x00,0x00,0xC3,0x00,0xf0,0x40,0x00,0x6f,0x4f,0x0f,0xEE,0x00,0x00,0x2f,0x5f,0x5f,0x5f,0x00,0x00,0x00};
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
//SRC nc nc nc SMUTE softS ss2 LOUD VOL TREB MIDR BASS S/M/B LFo RFo LRo RRo SWL SWR
// 4f
//Notes: (4)subWoofer set to input MUX, softmute 1ms,(3)SubW flat **08=Main VOL: set so with EQ flat RR Max FBK-1db is enough
byte tdaL[] = {//tda FX ini data<<<check SOME OF THESE
0x01,0x00,0x77,0x00,0x10,0x00,0x00,0x07,0x74,0xC7,0x00,0x60,0x03,0x60,0x20,0x60,0xd3,0x00};//was 66..
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
//SRC LOUD SMUTE VOL TREB MIDR BASS SRC2 S/M/B MIX LFo RFo LRo RRo MLEV SWo SPEC(MAY NEED ADJ)
byte tdaSub=0;
byte tdaData=0;
byte ditherFX=0x80;
byte ditherFXtoggle=0;
//********* SPI STUFF ***********
byte rxBuf0=0;
byte rxBuf1=0;
byte rxBuf2=0;
byte rxBuf3=0;
byte rxBuf4=0;
//******** SLICE STUFF **********
byte sliceStartAddr2[500];
byte sliceStartAddr1[500];
byte sliceStartAddr0[500];
byte sliceEndAddr2[500]; //may need these, may not
byte sliceEndAddr1[500];
byte sliceEndAddr0[500];
//********* CORE STUFF *********
//Buffers to load to core for all
//modes/functions/core routines
byte setFlags= 0x00;
byte retFlags= 0x00;
byte RP_ST_REC_AD0= 0x00;
byte RP_ST_REC_AD1= 0x00;
byte RP_ST_REC_AD2= 0x00;
byte FX_ST_REC_AD0= 0x00;
byte FX_ST_REC_AD1= 0x00;
byte FX_ST_REC_AD2= 0x00;
byte RP_R_REC_AD0= 0x00;
byte RP_R_REC_AD1= 0x00;
byte RP_R_REC_AD2= 0x00;
byte FX_L_REC_AD0= 0x00;
byte FX_L_REC_AD1= 0x00;
byte FX_L_REC_AD2= 0x00;
byte RP_ST_PLAY_AD0= 0x00;
byte RP_ST_PLAY_AD1= 0x00;
byte RP_ST_PLAY_AD2= 0x00;
byte FX_ST_PLAY_AD0= 0x00;
byte FX_ST_PLAY_AD1= 0x00;
byte FX_ST_PLAY_AD2= 0x00;
byte RP_R_PLAY_AD0= 0x00;
byte RP_R_PLAY_AD1= 0x00;
byte RP_R_PLAY_AD2= 0x00;
byte FX_L_PLAY_AD0= 0x00;
byte FX_L_PLAY_AD1= 0x00;
byte FX_L_PLAY_AD2= 0x00;
byte RP_ST_RECSTOP_AD0= 0x00;
byte RP_ST_RECSTOP_AD1= 0x00;
byte RP_ST_RECSTOP_AD2= 0x00;
byte FX_ST_RECSTOP_AD0= 0x00;
byte FX_ST_RECSTOP_AD1= 0x00;
byte FX_ST_RECSTOP_AD2= 0x00;
byte RP_R_RECSTOP_AD0= 0x00;
byte RP_R_RECSTOP_AD1= 0x00;
byte RP_R_RECSTOP_AD2= 0x00;
byte FX_L_RECSTOP_AD0= 0x00;
byte FX_L_RECSTOP_AD1= 0x00;
byte FX_L_RECSTOP_AD2= 0x00;
byte RP_ST_RECMAX_AD0= 0x00;
byte RP_ST_RECMAX_AD1= 0x00;
byte RP_ST_RECMAX_AD2= 0x00;
byte FX_ST_RECMAX_AD0= 0x00;
byte FX_ST_RECMAX_AD1= 0x00;
byte FX_ST_RECMAX_AD2= 0x00;
byte RP_R_RECMAX_AD0= 0x00;
byte RP_R_RECMAX_AD1= 0x00;
byte RP_R_RECMAX_AD2= 0x00;
byte FX_L_RECMAX_AD0= 0x00;
byte FX_L_RECMAX_AD1= 0x00;
byte FX_L_RECMAX_AD2= 0x00;
byte FX_ST_START_AD0= 0x00;
byte FX_ST_START_AD1= 0x00;
byte FX_ST_START_AD2= 0x00;
byte FX_L_START_AD0= 0x00;
byte FX_L_START_AD1= 0x00;
byte FX_L_START_AD2= 0x00;
byte FX_ST_END_AD0= 0x00;
byte FX_ST_END_AD1= 0x00;
byte FX_ST_END_AD2= 0x00;
byte FX_L_END_AD0= 0x00;
byte FX_L_END_AD1= 0x00;
byte FX_L_END_AD2= 0x00;
byte FX_ST_LOOP_AD0= 0x00;
byte FX_ST_LOOP_AD1= 0x00;
byte FX_ST_LOOP_AD2= 0x00;
byte FX_L_LOOP_AD0= 0x00;
byte FX_L_LOOP_AD1= 0x00;
byte FX_L_LOOP_AD2= 0x00;
//end of addr stuff
byte STUT_R_LSB = 0x00;
byte STUT_L_MSB = 0x00;
byte STUT_L_LSB = 0x00;
byte STUT_R_MSB = 0x00;
byte T0CON = 0x00;
byte T1CON = 0x00;
byte T2CON = 0x00;
byte T3CON = 0x00;
byte T4CON = 0x7E;
byte T5CON = 0x00;
byte T6CON = 0x00;
byte TMR0_STEP = 0x01;
byte TMR1_STEP = 0x01;
byte TMR3_STEP = 0x01;
byte TMR5_STEP = 0x01;
byte TMR0_HI = 0xFE;//DEFAULT TO 48KS/S
byte TMR0_LO = 0x0C;
byte TMR1_HI = 0xFE;
byte TMR1_LO = 0x0C;
byte TMR3_HI = 0xFE;
byte TMR3_LO = 0x0C;
byte TMR5_HI = 0xFE;
byte TMR5_LO = 0x0C;
byte PR4 = 0x00;
byte PR6 = 0x00;
byte ADC_CONV_TIME = 0x00;
byte GMOVE_SIZE = 0x00;
byte CTRL_FLAGS = 0x00;
byte MODE_FLAGS = 0x00;
long unsigned playRpSt=0;
//spectrum
byte specStep=0;
int specBand[8]={};
byte specCnt=0;
//*********************************************************SETUP***************************************************************
void setup() {
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.