edgeflame

Untitled

Jun 24th, 2024
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1.  
  2.  
  3. /*********************************************************************************
  4. **
  5. ** LVFA_Firmware - Provides Basic Arduino Sketch For Interfacing With LabVIEW.
  6. **
  7. ** Written By: Sam Kristoff - National Instruments
  8. ** Written On: November 2010
  9. ** Last Updated: Dec 2011 - Kevin Fort - National Instruments
  10. **
  11. ** This File May Be Modified And Re-Distributed Freely. Original File Content
  12. ** Written By Sam Kristoff And Available At www.ni.com/arduino.
  13. **
  14. *********************************************************************************/
  15.  
  16.  
  17. /*********************************************************************************
  18. **
  19. ** Includes.
  20. **
  21. ********************************************************************************/
  22. // Standard includes. These should always be included.
  23. #include <Wire.h>
  24. #include <SPI.h>
  25. #include <Servo.h>
  26. #include "LabVIEWInterface.h"
  27.  
  28. /*********************************************************************************
  29. ** setup()
  30. **
  31. ** Initialize the Arduino and setup serial communication.
  32. **
  33. ** Input: None
  34. ** Output: None
  35. *********************************************************************************/
  36. const int pwmOutPin = 9;
  37. unsigned long previousMillis = 0;
  38. const unsigned long interval = 10; // Update interval in milliseconds
  39. const float frequency = 1; // Frequency of the sine wave in Hz
  40. const float period = 1000.0 / frequency; // Period in milliseconds
  41.  
  42. void setup()
  43. {
  44. // Initialize Serial Port With The Default Baud Rate
  45. syncLV();
  46.  
  47. // Place your custom setup code here
  48. Serial.begin(9600);
  49. // initialize the digital pin as an output.
  50. pinMode(pwmOutPin, OUTPUT);
  51. }
  52. /*********************************************************************************
  53. ** loop()
  54. **
  55. ** The main loop. This loop runs continuously on the Arduino. It
  56. ** receives and processes serial commands from LabVIEW.
  57. **
  58. ** Input: None
  59. ** Output: None
  60. *********************************************************************************/
  61. void loop()
  62. {
  63. unsigned long currentMillis = millis();
  64.  
  65. if (currentMillis - previousMillis >= interval) {
  66. previousMillis = currentMillis;
  67.  
  68. float x = (currentMillis % (unsigned long)period) / period * 2 * PI;
  69. int sinValue = (sin(x)* 300) ;
  70.  
  71. analogWrite(pwmOutPin, sinValue);
  72. Serial.println(sinValue);
  73. delay(5);
  74. }
  75.  
  76. }
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
Advertisement
Add Comment
Please, Sign In to add comment