Pages: [1]   Go Down
Author Topic: Reading the state of a pin in C#  (Read 551 times)
0 Members and 1 Guest are viewing this topic.
Denmark
Offline Offline
Newbie
*
Karma: 0
Posts: 2
me who?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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


Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 438
Posts: 23718
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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)
}
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Global Moderator
Netherlands
Online Online
Shannon Member
*****
Karma: 169
Posts: 12441
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

google arduino c# serial => 365.000 hits 0.18 seconds smiley

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

Rob Tillaart

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

Denmark
Offline Offline
Newbie
*
Karma: 0
Posts: 2
me who?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you both now i have something to work with.
Logged

Pages: [1]   Go Up
Jump to: