Sulaymaniyah-Kurdistan
Offline
Jr. Member
Karma: 0
Posts: 89
|
 |
« on: February 01, 2013, 02:23:45 pm » |
hello everyone i want to covert to the value of the degree to direction //All this does is read the heading from HMC6352 and spit it out via serial
#include <Wire.h> int HMC6352SlaveAddress = 0x42; int HMC6352ReadAddress = 0x41; //"A" in hex, A command is:
int headingValue;
void setup(){ // "The Wire library uses 7 bit addresses throughout. //If you have a datasheet or sample code that uses 8 bit address, //you'll want to drop the low bit (i.e. shift the value one bit to the right), //yielding an address between 0 and 127." HMC6352SlaveAddress = HMC6352SlaveAddress >> 1; // I know 0x42 is less than 127, but this is still required
Serial.begin(9600); Wire.begin(); }
void loop(){ //"Get Data. Compensate and Calculate New Heading" Wire.beginTransmission(HMC6352SlaveAddress); Wire.write(HMC6352ReadAddress); // The "Get Data" command Wire.endTransmission();
//time delays required by HMC6352 upon receipt of the command //Get Data. Compensate and Calculate New Heading : 6ms delay(6);
Wire.requestFrom(HMC6352SlaveAddress, 2); //get the two data bytes, MSB and LSB
//"The heading output data will be the value in tenths of degrees //from zero to 3599 and provided in binary format over the two bytes." byte MSB = Wire.read(); byte LSB = Wire.read();
int headingSum = (MSB << 8) + LSB; //(MSB / LSB sum) headingSum = headingSum / 10; int value = headingSum ; Serial.print(headingSum);
if (value > 68 || value < 112) { Serial.println("E"); }
delay(500); } but the result are wrong the if statement doesn't work any one can help me? thanks for replaying
|
|
|
|
|
Logged
|
|
|
|
|
Queens, New York
Offline
Edison Member
Karma: 28
Posts: 1551
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
|
 |
« Reply #1 on: February 01, 2013, 02:30:21 pm » |
What does Serial.print(headingSum); put out?
|
|
|
|
|
Logged
|
UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino
Arduino Tutorials, coming soon.
"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown
|
|
|
|
Sulaymaniyah-Kurdistan
Offline
Jr. Member
Karma: 0
Posts: 89
|
 |
« Reply #2 on: February 01, 2013, 02:31:40 pm » |
|
|
|
|
|
Logged
|
|
|
|
|
Finland
Offline
Jr. Member
Karma: 1
Posts: 84
|
 |
« Reply #3 on: February 01, 2013, 02:33:57 pm » |
if (value > 68 || value < 112) looks like a statement that is always true to me.. how about if (value > 68 && value < 112)
|
|
|
|
|
Logged
|
|
|
|
|
Queens, New York
Offline
Edison Member
Karma: 28
Posts: 1551
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
|
 |
« Reply #4 on: February 01, 2013, 02:35:18 pm » |
Ok, what should it say?
|
|
|
|
|
Logged
|
UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino
Arduino Tutorials, coming soon.
"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown
|
|
|
|
Sulaymaniyah-Kurdistan
Offline
Jr. Member
Karma: 0
Posts: 89
|
 |
« Reply #5 on: February 01, 2013, 02:35:38 pm » |
&& can't be if one if them true it will be true
|
|
|
|
|
Logged
|
|
|
|
|
Sulaymaniyah-Kurdistan
Offline
Jr. Member
Karma: 0
Posts: 89
|
 |
« Reply #6 on: February 01, 2013, 02:37:28 pm » |
thanks it is workings  107E 107E 106E 106E 106E 100E 86E 69E 62503726208103336506377E 88E 94E 101E 103E 104E 112124135134134133134132133133132133132132134132132132132132132132132132132135
|
|
|
|
|
Logged
|
|
|
|
|
Queens, New York
Offline
Edison Member
Karma: 28
Posts: 1551
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
|
 |
« Reply #7 on: February 01, 2013, 02:39:43 pm » |
Working? 107E 107E 106E 106E 106E 100E 86E 69E 62503726208103336506377E 88E 94E 101E 103E 104E 112124135134134133134132133133132133132132134132132132132132132132132132132135
What changed, the &&?
|
|
|
|
|
Logged
|
UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino
Arduino Tutorials, coming soon.
"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown
|
|
|
|
Sulaymaniyah-Kurdistan
Offline
Jr. Member
Karma: 0
Posts: 89
|
 |
« Reply #8 on: February 01, 2013, 02:41:38 pm » |
if (value > 68 && value < 112) { Serial.println("E"); } if (value > 23 && value < 67) { Serial.println("NE"); } if (value > 338 && value < 22) { Serial.println("N"); } if (value > 293 && value < 337) { Serial.println("NW"); } if (value > 248 && value < 292) { Serial.println("W"); } if (value > 202 && value < 247) { Serial.println("SW"); } if (value > 158 && value < 201) { Serial.println("S"); } if (value > 113 && value < 157) { Serial.println("SE"); }
And i get SE SE SE SE E E E E E E NE NE NE NE NW
|
|
|
|
|
Logged
|
|
|
|
|
Queens, New York
Offline
Edison Member
Karma: 28
Posts: 1551
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
|
 |
« Reply #9 on: February 01, 2013, 02:49:15 pm » |
Ok Great.
How about a challenge, make it so that it only shows one direction at a time, until the direction is changed. Think you can do it?
|
|
|
|
|
Logged
|
UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino
Arduino Tutorials, coming soon.
"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown
|
|
|
|
Sulaymaniyah-Kurdistan
Offline
Jr. Member
Karma: 0
Posts: 89
|
 |
« Reply #10 on: February 01, 2013, 02:52:49 pm » |
li didn't understand . can u make it clearly?
|
|
|
|
|
Logged
|
|
|
|
|
Queens, New York
Offline
Edison Member
Karma: 28
Posts: 1551
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
|
 |
« Reply #11 on: February 01, 2013, 02:54:41 pm » |
You get this SE SE SE SE E E E E E E NE NE NE NE NW
make it so that you only get SE E NE NW
You don't have to, its your code, you can do whatever you want. Its just a suggestion to try.
|
|
|
|
|
Logged
|
UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino
Arduino Tutorials, coming soon.
"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown
|
|
|
|
Sulaymaniyah-Kurdistan
Offline
Jr. Member
Karma: 0
Posts: 89
|
 |
« Reply #12 on: February 01, 2013, 02:56:46 pm » |
thanks for the idea but i can't do it?
|
|
|
|
|
Logged
|
|
|
|
|
Netherlands
Offline
Tesla Member
Karma: 88
Posts: 9392
In theory there is no difference between theory and practice, however in practice there are many...
|
 |
« Reply #13 on: February 01, 2013, 05:26:16 pm » |
you might like this thread - http://arduino.cc/forum/index.php/topic,94507.0.html - to convert degrees to direction
|
|
|
|
|
Logged
|
|
|
|
|
|