// Ohmmetro V1.1 By Valter & Samuele (Nov. 2007) #include "NXTDefs.h" dseg segment RAW_read word // RAW value read up dword // value calculated numerator fraction down word // value calculated denominator fraction resistor dword // value calculated resistance resistorKohm word // value calculated resistance in Kohms dseg ends /* ---------------------------- START PROGRAM -------------------------*/ thread main SetSensorType (IN_1, IN_TYPE_SWITCH) SetSensorMode (IN_1, IN_MODE_RAW) loop: ReadSensor(IN_1,RAW_read) mul up, 10000, RAW_read // calculation numerator sub down, 1023, RAW_read // calculation denominator div resistor, up, down // calculation resistance brcmp EQ, Else, resistor, 0 // if value is equal to 0 ... Then: // ... go to Else ClearScreen() TextOut(12, 8, ' ohm') NumOut(50, 8, resistor) // display value in ohms brcmp LTEQ, onlyohm, resistor, 10000 // if value <= 10000 -> NO Kohms div resistorKohm, resistor, 1000 // calculation resistance in Kohms TextOut(12, 24, 'Kohm') // display value in Kohms NumOut(50, 24, resistorKohm) onlyohm: jmp EndIf Else: // display (infinite) ClearScreen() TextOut(20, 16, '(Infinite)') TextOut(6, 8, 'Insert Resistor') EndIf: TextOut(13, 48, 'Ohmmetro V1.1') TextOut(3, 44, 'By Valter & Samu') wait 400 // pause 0,4 sec (reading data) jmp loop // return to main loop exit endt /* ---------------------------- END PROGRAM -------------------------*/