Hardware Reference
In-Depth Information
Listing 16-3 continued
} // all bits in
digitalWrite( CK_ENC, HIGH); // clock high
delayMicroseconds(10);
reading[i] = hallReading;
}
digitalWrite( CS_ENC, HIGH); // remove chip enable
// all data in now process the data
int errorLEDs = 0;
for(int i=0; i<npRead; i++){
th[i] = ((reading[i] >> 6) & 0x3ff) - offset[i];
//angle data
th[i] = th[i] * 0.006135; // convert into radians
if((reading[i] & 0x6) != 0) errorLEDs++;
// shows an error
}
if(errorLEDs != 0) digitalWrite(A5,HIGH);
else digitalWrite(A5,LOW); // drive error LED
}
void upDateLEDs(int n){ // MS nibble red - LS nibble green
ledsOff();
for(int i = 0; i<4; i++){
if( (n & 1) != 0) digitalWrite(ledGreen[i],HIGH);
n = n >> 1;
}
for(int i = 0; i<4; i++){
if( (n & 1) != 0) digitalWrite(ledRed[i],HIGH);
n = n >> 1;
}
}
void ledsOff(){
for(int i=0; i<4; i++){
digitalWrite(ledRed[i], LOW);
digitalWrite(ledGreen[i], LOW);
}
}
void sendData() { // send X Y points to plot
int s1,s2;
byte t;
// pendulums 1 and 3 are short and so have a wider range
Search WWH ::




Custom Search