Hardware Reference
In-Depth Information
switch(np) {
case 2: // from two pendulums
s1 = OFFSET + (RANGE * sin(th[0]));
s2 = OFFSET + (RANGE * sin(th[2]));
break;
case 3: // from three pendulums
s1 = OFFSET + (H_RANGE * sin(th[0])) + ;
(H_OFFSET * sin(th[1]));
s2 = OFFSET + (RANGE * sin(th[2]));
break;
case 4: // from four pendulums
s1 = OFFSET + (H_RANGE * sin(th[0])) + ;
(H_OFFSET * sin(th[1]));
s2 = OFFSET + (H_RANGE * sin(th[2])) + ;
(H_OFFSET * sin(th[3]));
break;
case 5: // from other two pendulums
s1 = OFFSET + (OFFSET * sin(th[1]));
s2 = OFFSET + (OFFSET * sin(th[3]));
case 6: // from three pendulums
s1 = OFFSET + (RANGE * sin(th[0]));
s2 = OFFSET + (H_RANGE * sin(th[2]) + ;
(H_OFFSET * sin(th[3])));
break;
}
// split up the data into 4 bytes, tag top
// two MS bits and send
t = (s1 >> 5) & 0x1f; // MSB first
Serial.write(t);
t = (s1 & 0x1f) | 0x40; // LSB plus top index bits
Serial.write(t);
t = ((s2 >> 5) & 0x1f)| 0x80; // MSB plus top index bit
Serial.write(t);
t = (s2 & 0x1f) | 0xC0; // LSB plus top index bits
Serial.write(t);
}
he irst thing to note is that the line
int offset[] = {521, 510, 380, 477}; // offsets at zero degrees
should be changed to the readings you took with the previous sketch when the pendulums were
hanging down. It is impossible that you will have the same readings here for your construction.
Search WWH ::




Custom Search