help with arrays and procedures


i'm trying write procedure reads value array, , depending on value things. follows

code: [select]
// arduino output pins
#define shdn 51
#define cs 49
#define clock  45
#define datain  43
#define dataout 47
#define chn1 48
#define chn2 44
#define chn3 46
#define chn4 50

// 2us of clock period ( sample rate = 30.3 khz)


#define half_clock_period 1
uint8_t j=0;
void setup()
{
 pinmode(datain, output);
 pinmode(dataout, input);
 pinmode(clock, output);
 pinmode(cs, output);
 pinmode(shdn, output);
 digitalwrite (datain, low);
 digitalwrite (clock, low);
 digitalwrite (cs, low);
 digitalwrite (shdn, low);
  serial.begin(9600);
  int address[8]={0,0,0,0,0,0,0,1};
}
void writevalue( int address[8], uint8_t value){

 digitalwrite (cs, low);
 digitalwrite (shdn, high);
 digitalwrite (clock, low);
 //send 8 bit address array
for(int i=7; i>=0;i--){
   if (address[i]==1){
     digitalwrite(datain, high);
   
   }
   else if (address[i]==0){
      digitalwrite (datain, low);
     
   }
   if(address[i]!=1||0){
   serial.print("unrecognized. 1 , 0 recognized\n");
   break;
 }
 
 delaymicroseconds(half_clock_period);
 digitalwrite (clock, high);
 delaymicroseconds(half_clock_period);
 digitalwrite (clock, low);
}
 
// send 8 bit sample data
for(int i=7;i>=0;i--){
  digitalwrite(datain,((value&(1<<i)))>>i);
  delaymicroseconds(half_clock_period);
 digitalwrite (clock, high);
 delaymicroseconds(half_clock_period);
 digitalwrite (clock, low);
}
// latch enable dac output set
digitalwrite(datain,low);
digitalwrite(clock,low);
digitalwrite(cs,high);
delaymicroseconds(half_clock_period);
digitalwrite(cs,low);
}
void loop ()
{
 int address[8]={0,0,0,0,0,0,0,1};
 //a 0 5v triangular waveform
 //for(j=0;j<255;j+=5){
   writevalue(address,255); //error: invalid conversion 'uint8_t' 'int*'
   //writevalue(address,0);
 //}
//  for(j=0;j<255;j+=5){
//    writevalue(address,255-j);
//  }
}

 


what want take ith value of array, , if 1 turn on, if 0 turn thing off, if chance 2 print error message. , starting @ 7, , going down 0.

however instead of in case having 1 pin turned on, because there single 1, pins turned on, , cannot figure out why.

thsi:
quote
int address[8]={0,0,0,0,0,0,0,1};

at end of setup isn't useful thing do.
you create array "address" mere microseconds before goes out of scope , lost forever.

code: [select]
 if(address[i]!=1||0){
is incorrect. 1 | 0 1.


Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > help with arrays and procedures


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums