Pages: [1]   Go Down
Author Topic: Please Help :D  (Read 289 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello there... new to the forums. Hello all!. I'm new to arduino and C programming. I'm familiar with programming in assembly language and was wondering if i could get a little assistance in a particular function i want to accomplish. Im using a distance sensor and want to compare readings from two different directions and have it decide which direction has a greater distance. In assembly i could store data and do a mathematical comparison to decide. Haven't been able to figure out how in C.

Idea:
Distance 1 Data Read
Distance 2 Data Read
Distance 1 - Distance 2 = X
X>0 ; Do something
X<0; Do something else

Thanks in Advanced smiley-grin
Logged

UK
Offline Offline
Faraday Member
**
Karma: 99
Posts: 4153
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Read the data into variable.
Compare the variables.

Code:
int distance1 = getDistanceFromWhateverDeviceThisIs(0);
int distance2 = getDistanceFromWhateverDeviceThatIs(1);

if (distance1 > distance2) {
  // Do something
} else {
  // Do something else
}
Logged

Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thank you... i will try this out smiley-grin
Logged

Pages: [1]   Go Up
Jump to: