Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*********************************************************************************
- **
- ** LVFA_Firmware - Provides Basic Arduino Sketch For Interfacing With LabVIEW.
- **
- ** Written By: Sam Kristoff - National Instruments
- ** Written On: November 2010
- ** Last Updated: Dec 2011 - Kevin Fort - National Instruments
- **
- ** This File May Be Modified And Re-Distributed Freely. Original File Content
- ** Written By Sam Kristoff And Available At www.ni.com/arduino.
- **
- *********************************************************************************/
- /*********************************************************************************
- **
- ** Includes.
- **
- ********************************************************************************/
- // Standard includes. These should always be included.
- #include <Wire.h>
- #include <SPI.h>
- #include <Servo.h>
- #include "LabVIEWInterface.h"
- /*********************************************************************************
- ** setup()
- **
- ** Initialize the Arduino and setup serial communication.
- **
- ** Input: None
- ** Output: None
- *********************************************************************************/
- const int pwmOutPin = 9;
- unsigned long previousMillis = 0;
- const unsigned long interval = 10; // Update interval in milliseconds
- const float frequency = 1; // Frequency of the sine wave in Hz
- const float period = 1000.0 / frequency; // Period in milliseconds
- void setup()
- {
- // Initialize Serial Port With The Default Baud Rate
- syncLV();
- // Place your custom setup code here
- Serial.begin(9600);
- // initialize the digital pin as an output.
- pinMode(pwmOutPin, OUTPUT);
- }
- /*********************************************************************************
- ** loop()
- **
- ** The main loop. This loop runs continuously on the Arduino. It
- ** receives and processes serial commands from LabVIEW.
- **
- ** Input: None
- ** Output: None
- *********************************************************************************/
- void loop()
- {
- unsigned long currentMillis = millis();
- if (currentMillis - previousMillis >= interval) {
- previousMillis = currentMillis;
- float x = (currentMillis % (unsigned long)period) / period * 2 * PI;
- int sinValue = (sin(x)* 300) ;
- analogWrite(pwmOutPin, sinValue);
- Serial.println(sinValue);
- delay(5);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment