Academic Hardware Products (myDAQ, myRIO)

cancel
Showing results for 
Search instead for 
Did you mean: 

Can someone teach me how to code?

So anyways, the code attached in this file wirtten by someone else. 

 

What this code does is, if detect port0/line1 digital input, wait 100ms, send digital output to port0/line2. 

 

I want to edit the code so that it does the following 

If detect digital input port0/line1 (sensor)

   wait 100ms;

    send digital output to port0/line2 (turn on red led)

   wait 2000ms

    send a reverse output to port0/line2 (turn off red led)

 

If detect digital input port0/line3 (sensor)

   wait 100ms;

    send digital output to port0/line4 (turn on green led)

   wait 2000ms

    send a reverse output to port0/line4 (turn off green led)

 

The code have to run continously. 

 

           

0 Kudos
Message 1 of 14
(8,267 Views)

Hey Hunkeelin,

 

We can certainly help you get this code working.  What part are you having trouble with?

 

If you're new to LabVIEW check out the Self Paced LabVIEW training here: https://learn.ni.com/learn/article/labview-tutorial

 

-Sam K

LabVIEW Hacker

Join / Follow the LabVIEW Hacker Group on google+

0 Kudos
Message 2 of 14
(8,262 Views)

Ok. I have no problem doing the first if loop, but I have trouble making the second if loop (LED blue).

0 Kudos
Message 3 of 14
(8,253 Views)

You also seem to have a problem explaining your problem. You have no blue LED in your question. To control the green LED, you simply copy and paste existing code and change the line numbers and task names. From your description, you don't have any relationship between monitoring line 1 and line 3 so the copy/paste should work. You could also use a single tasks for reading and writing.

0 Kudos
Message 4 of 14
(8,234 Views)

I see. So how can I turn off the LED?

0 Kudos
Message 5 of 14
(8,228 Views)

Send the opposite logic level that you use to turn the LED on.

0 Kudos
Message 6 of 14
(8,224 Views)

Yea, how exaclty do I do that in labview? I only see send digital signal. 

0 Kudos
Message 7 of 14
(8,219 Views)

Exactly. You send out a digital signal to turn on or off your external LED. In your explanation, this is what you have defined as  port0/line2, correct? You can also had a front panel Boolean indicator to show the state of the hardware. 

0 Kudos
Message 8 of 14
(8,213 Views)

Hey hunkeelin,

 

It sounds like you're pretty new to LabVIEW and DAQmx.

 

I highly recommend you take a step back and start with some simple examples.   As I mentioned in my first post you can find some great tutorials for getting started with LabVIEW here : https://learn.ni.com/learn/article/labview-tutorial

 

An introduction to Data Acquisition here: https://www.ni.com/en/shop/data-acquisition.html

 

And lots of information on DAQmx here: https://www.ni.com/en/support/documentation/supplemental/06/getting-started-with-ni-daqmx--main-page...

 

From your first post it sounds like you have some code you got from someone else and just want it to work, but I highly recommend you take the time to go through some of this getting started material to understand how the code works and how to can change it to do anything you need.  It will really be worth your time in the long run.

 

Please let us know if you have additional questions.

 

Thanks!

 

-Sam K

LabVIEW Hacker

Join / Follow the LabVIEW Hacker Group on google+

0 Kudos
Message 9 of 14
(8,200 Views)

Anyway, I went through some the labs, it's helpful but not something I want. I will learn along the way, but the labview part is a very small part of my project. For me to write the if loop all my byself  (which seems easy because the guy in this forum who help me out only took 15 min of his time) will take weeks or months. Best if someone could modify my code where it could send a opposite logical signal after 200ms for the LED. 

 

Anyways, for my learning purpose:

 

1) I am suspecting there should be a modification in DAQmx write but I am really not sure. I code in matlab and c/c++ labview seems to be completely different. I don't even see an "if loop" here. 

 

 

Thanks.

0 Kudos
Message 10 of 14
(8,188 Views)