Editing Hack Notes CVA 090324
Jump to navigation
Jump to search
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 57: | Line 57: | ||
for(int i = BitsCount; i >= 0; i--) { | for(int i = BitsCount; i >= 0; i--) { | ||
digitalWrite(CLK_pin, LOW); | digitalWrite(CLK_pin, LOW); | ||
if ((Value | if ((Value & 1 << i) == ( 1 << i)) { | ||
digitalWrite(DIO_pin, HIGH); | digitalWrite(DIO_pin, HIGH); | ||
//Serial.print("1"); | //Serial.print("1"); | ||
Line 97: | Line 97: | ||
// the integer. | // the integer. | ||
// see: http://en.wikipedia.org/wiki/Two%27s_complement | // see: http://en.wikipedia.org/wiki/Two%27s_complement | ||
if ((ShiftIn_result | if ((ShiftIn_result & 1 << 11) == 1 << 11) { | ||
ShiftIn_result = (B11111000 << 8) | ShiftIn_result; | ShiftIn_result = (B11111000 << 8) | ShiftIn_result; | ||
} | } | ||
Line 142: | Line 142: | ||
void loop() { | void loop() { | ||
if (millis() - serialTimer > 50 ) { | if ((millis() - serialTimer) > 50 ) { | ||
//read compass and print data to lcd and serial out | //read compass and print data to lcd and serial out | ||
Line 167: | Line 167: | ||
lcd.printIn(" "); | lcd.printIn(" "); | ||
digitalWrite(EN_pin, HIGH); // ok deselect chip | digitalWrite(EN_pin, HIGH); // ok deselect chip | ||
angle = 180 * (atan2(-Y_Data , X_Data) / M_PI); // angle is atan( -y/x) !!! | angle = 180 * (atan2(-1 * Y_Data , X_Data) / M_PI); // angle is atan( -y/x) !!! | ||
Serial.print(angle); // print angle | Serial.print(angle); // print angle | ||
sprintf(string, "%4d", angle); | sprintf(string, "%4d", angle); | ||
Line 300: | Line 300: | ||
for(int i = BitsCount; i >= 0; i--) { | for(int i = BitsCount; i >= 0; i--) { | ||
digitalWrite(CLK_pin, LOW); | digitalWrite(CLK_pin, LOW); | ||
if ((Value | if ((Value & 1 << i) == ( 1 << i)) { | ||
digitalWrite(DIO_pin, HIGH); | digitalWrite(DIO_pin, HIGH); | ||
//Serial.print("1"); | //Serial.print("1"); | ||
Line 340: | Line 340: | ||
// the integer. | // the integer. | ||
// see: http://en.wikipedia.org/wiki/Two%27s_complement | // see: http://en.wikipedia.org/wiki/Two%27s_complement | ||
if ((ShiftIn_result | if ((ShiftIn_result & 1 << 11) == 1 << 11) { | ||
ShiftIn_result = (B11111000 << 8) | ShiftIn_result; | ShiftIn_result = (B11111000 << 8) | ShiftIn_result; | ||
} | } | ||
Line 385: | Line 385: | ||
void loop() { | void loop() { | ||
if (millis() - serialTimer > 2200 ) { | if ((millis() - serialTimer) > 2200 ) { | ||
//read compass and print data to lcd and serial out | //read compass and print data to lcd and serial out | ||
Line 410: | Line 410: | ||
lcd.printIn(" "); | lcd.printIn(" "); | ||
digitalWrite(EN_pin, HIGH); // ok deselect chip | digitalWrite(EN_pin, HIGH); // ok deselect chip | ||
angle = 180 * (atan2(-Y_Data , X_Data) / M_PI); // angle is atan( -y/x) !!! | angle = 180 * (atan2(-1 * Y_Data , X_Data) / M_PI); // angle is atan( -y/x) !!! | ||
Serial.print(angle); // print angle | Serial.print(angle); // print angle | ||
sprintf(string, "%4d", angle); | sprintf(string, "%4d", angle); |