Go Down

Topic: Help with newbie code (Read 587 times) previous topic - next topic

JayBee

Feb 09, 2012, 06:01 pm Last Edit: Feb 09, 2012, 06:30 pm by JayBee Reason: 1
Here is my code:

Code: [Select]
#include <SPI.h>

//define output pins

#define DATAOUT 11 //MOSI
#define DATAIN 12 //MISO
#define SPICLOCK 13 //SCK
#define SLAVESELECT 10 //SSB
#define INPUTPIN 2 //Sensor input


//variables

byte index1 = 0;
byte index2 = 0;
byte j;
byte Playaddress = B10010110; // 0xA6

void setup()
{
Serial.begin (9600);  // to see what is happening during run
SPI.begin();  //start SPI
SPI.setBitOrder(MSBFIRST);  // MSB first
SPI.setClockDivider(SPI_CLOCK_DIV4);  // SPI clock is system/4
SPI.setDataMode (SPI_MODE3);  // SPI mode 3
INPUTPIN == HIGH;

pinMode (DATAOUT, OUTPUT);
pinMode (DATAIN, INPUT);
pinMode (SPICLOCK, OUTPUT);
pinMode (SLAVESELECT, OUTPUT);
digitalWrite (SLAVESELECT, HIGH); //disable device
digitalWrite (SPICLOCK, HIGH); //set clock to high for inactive mode

// SPCR = 01011000
//disables SPI interrupt, enables SPI, MSB first, Arduino is master
//inactive clock is high, rising edge active, 4 Mhz clock
//SPCR =(1<<SPE | 1<<MSTR |1<<CPOL)
//clr=SPSR
//clr=SPDR
}

byte makesound (index1, index2){  //make sound procedure

 digitalWrite (SLAVESELECT, LOW);  //selects ISD3900
 SPI.transfer (Playaddress);  //sends address for Play command
 SPI.transfer (index1);  //first byte of sound
 SPI.transfer (index2);  //2nd byte of sound
 digitalWrite (SLAVESELECT, HIGH);   //deselects ISD3900
}

void loop()
{
index1=0001100;
index2=0010011;
if (INPUTPIN == LOW)
makesound (index1, index2);
}


I get error messages:
'index1' was not declared in this scope
'index2' was not declared in this scope
initializer expression list treated as compound expression

There are others but I think that I can figure them out.  Any help for this duffer?

mcleung

#1
Feb 09, 2012, 06:12 pm Last Edit: Feb 09, 2012, 06:33 pm by mcleung Reason: 1
byte index1 = 0;

In you loop, you are missing a B (binary)
or else you would be passing a fairly large number, and that can't be saved as a byte!

Quote
index1= B0001100;
index2= B0010011;

JayBee

Thanks but that does not seem to have changed anything.

mcleung

#3
Feb 09, 2012, 06:18 pm Last Edit: Feb 09, 2012, 06:32 pm by mcleung Reason: 1
Also, the way you got it setup now, INPUTPIN will never go low, nor high, as you defined it as a constant.

I think what you'd want is:
if (digitalRead(INPUTPIN)==LOW)

Also, I just tested your code. The error is coming from your function makesound. You didn't define what the inputs where.

Quote
Void makesound (byte index1, byte index2){


Edit: I changed makesound to void, as you aren't returning anything anyways. Code compiles on my machine with no errors, although I don't think it will do what you expect it to do. Check over your INPUTPIN. Remember that define replaces all instances of INPUTPIN by 2, so in your Setup code, you are making INPUTPIN == HIGH; will return true, but that isn't changing anything?

AWOL

It has changed something.
Trust us.

When posting code, please use the # icon on the editors toolbar to put the code into a code box.
Please go back to your post, click on "modify', highlight the code, click on the # icon, then click on "save".

Also, why bother commenting a binary constant with the hex value which doesn't reflect the binary value?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

mmcp42

hmm
I tried to compile it
getting the same error
index1 and index2 look to be declared correctly

I ignored the code doing odd things
why doesn't it compile?!?
there are only 10 types of people
them that understands binary
and them that doesn't

dxw00d

Post the code again. In code tags.

mmcp42

aha
your declaration of makesound should include the types!

Code: [Select]

byte makesound (byte index1, byte index2)

however why are you
a) declaring index1, index2 as global
b) initialising them
c) passing them as parameters
???
there are only 10 types of people
them that understands binary
and them that doesn't

JayBee

Got it.  I put the code into a code box, sorry about that.  I will make the mods suggested here and go from there.  INPUTPIN will be a hardware switch for test purposes and then a sensor input in the final project.

Thanks for all the help.

Go Up