I'm trying to write a procedure that reads a value from an array, and depending on its value does certain things. It is as follows
// 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 a 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 the 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. Only 1 and 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 is 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 to 5V triangular waveform
//for(j=0;j<255;j+=5){
writeValue(address,255); //error: invalid conversion from 'uint8_t' to 'int*'
//writeValue(address,0);
//}
// for(j=0;j<255;j+=5){
// writeValue(address,255-j);
// }
}
What I want it to do is to take the ith value of the array, and if it is a 1 turn it on, if it is a zero turn the thing off, if by chance it is a 2 print an error message. and do this starting at 7, and going down to 0.
however instead of in this case only having 1 pin turned on, because there is only a single 1, all the pins are turned on, and I cannot figure out why.