Pages: [1]   Go Down
Author Topic: Help with newbie code  (Read 440 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is my code:

Code:
#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?
« Last Edit: February 09, 2012, 12:30:31 pm by JayBee » Logged

Canada
Offline Offline
Newbie
*
Karma: 1
Posts: 24
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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;
« Last Edit: February 09, 2012, 12:33:24 pm by mcleung » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks but that does not seem to have changed anything.
Logged

Canada
Offline Offline
Newbie
*
Karma: 1
Posts: 24
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
« Last Edit: February 09, 2012, 12:32:47 pm by mcleung » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25732
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

"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.

Leighton Buzzard, UK
Offline Offline
Edison Member
*
Karma: 21
Posts: 1339
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?!?
Logged

there are only 10 types of people
them that understands binary
and them that doesn't

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Post the code again. In code tags.
Logged

Leighton Buzzard, UK
Offline Offline
Edison Member
*
Karma: 21
Posts: 1339
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

aha
your declaration of makesound should include the types!

Code:
byte makesound (byte index1, byte index2)
however why are you
a) declaring index1, index2 as global
b) initialising them
c) passing them as parameters
???
Logged

there are only 10 types of people
them that understands binary
and them that doesn't

Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1]   Go Up
Jump to: