Go Down

Topic: Please Help :D (Read 316 times) previous topic - next topic

lloenll

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 :D

majenko

Read the data into variable.
Compare the variables.

Code: [Select]

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

if (distance1 > distance2) {
  // Do something
} else {
  // Do something else
}
Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

lloenll

thank you... i will try this out :D

Go Up