Using interrupt

hi everyone
I read all of about this lesson but I didnt find out how to use interrupt completely

for example: when I press button I want to toogle my led

but main question is that I have 8 input its value 1 or 0 when one of them change, I need to calculate sum of them again

how can I do this

thanks for your helps

Keep values in an array. Update them accordingly with interrupt handler and you can use do you sum using the array.

can u show me little example coz I didnt get it exactly

Can you tell more about your project. What are you trying to do?

ok

I have 8 input (sensor) I will read all of value 1 or 0 and I will calculate them spesific way for example
SUM=D1X1+D2X2+D3X4+D4X8+D5X16+D6X32+D7X64+D8X128

IF (SUM<32)
Something

else if (sum>32)
something

but I need to do this when one of them change

So you are assigning a binary weight to each sensor?

Do something like:


SavedValue = SavedValue & ~(1 << SensorNumber); // clear bit
SavedValue = SavedValue | (SensorValue << SensorNumber); //sets bit for sensor# if SensorValue = 1

The first line clears the bit for sensor ‘SensorNumber’ in the integer ‘SavedValue’. It does this by shifting a 1 into that bits position and takign the complement of that value. In other words you wind up with a 1 in every bit positon except the sensors bit position. When you logically AND SavedValue with this bitmask it clears the bit for this sensor.

The second line sets the sensors bit position it the sensor reading is 1, if the sensor reading is 0 then nothign is changed.

look in GHI hardware namespace for ParallelPort class. all in one solution.

That is a really good idea Mike. I think though that you would have to poll the parallel port state as it is deigned for bidirectional communications. One could use a timer to poll the parallel port state every 10ms or so and raise an event when it changed. I’m doing something similar right now with an I/O-40. I am polling all five input ports and checking for a change in value. In my case since I am interested in what input changed I have to compare the new port readings with the old and raise an event for each sensor (bit) that changed states.