1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
/*********************************************************************************
**
** 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 buttonPin = 2; // broche dédié au bouton
const int ledPin = 9; // broche dédié à la led
int buttonState = 0; // état du bouton
int lastButtonState = 0; // ancienne état du bouton
int ledState = 0; // état de la led
void setup()
{
// Initialize Serial Port With The Default Baud Rate
syncLV();
// Place your custom setup code here
pinMode(buttonPin, INPUT); // entrée
pinMode(ledPin, OUTPUT); // sortie
digitalWrite(7, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
}
/** 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()
{
// Check for commands from LabVIEW and process them.
checkForCommand();
// Place your custom loop code here (this may slow down communication with LabVIEW)
buttonState = digitalRead(buttonPin);//lecture de l'état du bouton
//Serial.println(buttonState);
//Serial.println(lastButtonState);
// si l'état du bouton est différent de l'état précedent
if (buttonState != lastButtonState)
{
if (buttonState == 1) // si l'état du bouton est high
{
if(ledState==1)
ledState=0;
else
ledState=1;
}
lastButtonState = buttonState; // nouvelle état du bouton
//Serial.print(lastButtonState);
}
digitalWrite(ledPin, ledState);//
delay(20);// délais anti-rebond
//Serial.println(ledState);
if (acqMode == 1)
{
sampleContinously();
}
// fin de la boucle globale
} |
Partager