Go Down

Topic: Reading the state of a pin in C# (Read 723 times) previous topic - next topic

Mean-Machine

Hi
I'm trying to read the state of a pin on the arduino and get the C# app to do a certain task, i know how to write to the arduino from the C# app, but i cant figure out how to get it to read the value of the pin ( high=1/low=0 ) from the serial and then make the app do a task ( ex. open a new form in the app or change the color of a box).
I just need the program to read the serial without showing the actual serial data, just do a task when it receives a 1 in the serial data, and do its task.

I have done a few c# programs before but only to send data over serial when a button is pressed or a event have been triggered.

Does anyone have an idea to do this, or could give me a few pointers how to do this? any help is appreciated



CrossRoads

Seems pretty simple:

if (Serial.available()>0){  // new byte came in?
incomingByte = Serial.read();  // read it
}
if ( (B00000001 & incomingByte)) == 1){ // is bit 0 a 1?
// do some action
}
else {
// do some other action (or leave this out if no other action)
}
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

robtillaart

google arduino c# serial => 365.000 hits 0.18 seconds :)

check - http://jtoee.com/2009/02/talking-to-an-arduino-from-net-c/ -  trick is   OnReceived()
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Mean-Machine

Thank you both now i have something to work with.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy