- #include <Wire.h>
- #include <SPI.h>
- #include <Servo.h>
- #include <HMC5883L.h>
- #include "LabVIEWInterface.h"
- HMC5883L compass;
- int error = 0;
- unsigned long millis_readsample = 0;
- unsigned long freq_readsample = 100;
- /*********************************************************************************
- ** setup()
- *********************************************************************************/
- void setup()
- {
- // Initialize Serial Port With The Default Baud Rate
- syncLV();
- // Place your custom setup code here
- Wire.begin();
- compass = HMC5883L();
- error = compass.SetScale(1.3);
- error = compass.SetMeasurementMode(Measurement_Continuous);
- millis_readsample = millis() + freq_readsample;
- }
- /*********************************************************************************
- ** loop()
- *********************************************************************************/
- void loop()
- {
- float var;
- // Check for commands from LabVIEW and process them.
- checkForCommand();
- // Place your custom loop code here (this may slow down communication with LabVIEW)
- if (millis() >= millis_readsample)
- {
- MagnetometerScaled scaled = compass.ReadScaledAxis();
- int xScaled = scaled.XAxis;
- int yScaled = scaled.YAxis;
- serialWriteFloat((float)xScaled);
- serialWriteFloat((float)yScaled);
- millis_readsample += freq_readsample;
- }
- }
- void serialWriteFloat(float arg)
- {
- byte * data = (byte *) &arg;
- Serial.write (data, sizeof (arg));
- }
- #[color=#5E6D03]include[/color] <Wire.h>
- #[color=#5E6D03]include[/color] <SPI.h>
- #[color=#5E6D03]include[/color] <[b][color=#d35400]Servo[/color][/b].h>
- #[color=#5E6D03]include[/color] <HMC5883L.h>
- #[color=#5E6D03]include[/color] [color=#005C5F]"LabVIEWInterface.h"[/color]
- HMC5883L compass;
- [color=#00979C]int[/color] [color=#5E6D03]error[/color] = 0;
- [color=#00979C]unsigned[/color] [color=#00979C]long[/color] millis_readsample = 0;
- [color=#00979C]unsigned[/color] [color=#00979C]long[/color] freq_readsample = 100;
- [color=#95a5a6]/*********************************************************************************[/color]
- [color=#95a5a6] ** setup()[/color]
- [color=#95a5a6]*********************************************************************************/[/color]
- [color=#00979C]void[/color] [color=#5E6D03]setup[/color]()
- {
- [color=#434F54]// Initialize Serial Port With The Default Baud Rate[/color]
- syncLV();
- [color=#434F54]// Place your custom setup code here[/color]
- Wire.[color=#D35400]begin[/color]();
- compass = HMC5883L();
- [color=#5E6D03]error[/color] = compass.SetScale(1.3);
- [color=#5E6D03]error[/color] = compass.SetMeasurementMode(Measurement_Continuous);
- millis_readsample = [color=#D35400]millis[/color]() + freq_readsample;
- }
- [color=#95a5a6]/*********************************************************************************[/color]
- [color=#95a5a6] ** loop()[/color]
- [color=#95a5a6]*********************************************************************************/[/color]
- [color=#00979C]void[/color] [color=#5E6D03]loop[/color]()
- {
- [color=#00979C]float[/color] var;
- [color=#434F54]// Check for commands from LabVIEW and process them.[/color]
- checkForCommand();
- [color=#434F54]// Place your custom loop code here (this may slow down communication with LabVIEW)[/color]
- [color=#5E6D03]if[/color] ([color=#D35400]millis[/color]() >= millis_readsample)
- {
- MagnetometerScaled scaled = compass.ReadScaledAxis();
- [color=#00979C]int[/color] xScaled = scaled.XAxis;
- [color=#00979C]int[/color] yScaled = scaled.YAxis;
- serialWriteFloat(([color=#00979C]float[/color])xScaled);
- serialWriteFloat(([color=#00979C]float[/color])yScaled);
- millis_readsample += freq_readsample;
- }
- }
- [color=#00979C]void[/color] serialWriteFloat([color=#00979C]float[/color] arg)
- {
- [color=#00979C]byte[/color] * data = ([color=#00979C]byte[/color] *) &arg;
- [b][color=#d35400]Serial[/color][/b].[color=#D35400]write[/color] (data, [color=#00979C]sizeof[/color] (arg));
- }
[text] code
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Editor
You can edit this paste and save as new: