Hardware Reference
In-Depth Information
Serial.println(dig2[i], HEX); // magnetic strength
}
count = count << 1;
if(count > 0xff) count = 1;
upDateLEDs(count);
error++ ;
digitalWrite(A5, error & 1); // flash error LED
Serial.println(“ “);
}
}
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 encRead(){ // reads two bytes from each encoder
int hallReading; // to hold 16 bits from sensor
digitalWrite( CS_ENC, LOW); // enable encoders
for(int i = 0; i<npRead; i++){ // read in each sensor
delayMicroseconds(50);
digitalWrite( CK_ENC, LOW); // clock low
delayMicroseconds(50);
for(int i=0;i<16;i++){
// read in all bits for one sensor
hallReading = hallReading << 1;
digitalWrite( CK_ENC, HIGH); // clock high
delayMicroseconds(50);
continued
Search WWH ::




Custom Search