Occasion Error: name '...' is not defined
Posted: Tue Nov 15, 2016 6:16 pm
Hello,
I am testing a part of my code which converts a binary number to decimal in the bitwise manner. But when I run I got error message " name 'dcmltemp' is not defined " (please refer to the following code for variable name) If I keep run it 2 or 3 times the error goes away and gives correct result. Then, I run it again, the error comes up again.
I cannot see what I did wrong in the code. Please help.
Thanks in advance.
I am testing a part of my code which converts a binary number to decimal in the bitwise manner. But when I run I got error message " name 'dcmltemp' is not defined " (please refer to the following code for variable name) If I keep run it 2 or 3 times the error goes away and gives correct result. Then, I run it again, the error comes up again.
I cannot see what I did wrong in the code. Please help.
Thanks in advance.
Code: Select all
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
clkPin = 23
misoPin = 21
mosiPin = 19
drdy_bPin = 15
GPIO.setup(clkPin, GPIO.OUT)
GPIO.setup(misoPin, GPIO.IN)
GPIO.setup(mosiPin, GPIO.OUT)
GPIO.setup(drdy_bPin, GPIO.IN)
if (GPIO.input(drdy_bPin)): #Data ready is active low
voltage = 'Waiting for ADC output :)'
else:
dcmltemp = 0
dcmlValue = 0
p = 0
check = 0
tempbinValue = 5 # give for test
tempbinValueNew = 5 #give for test
for i in range(0, 4):
check = tempbinValueNew & 1
if(check == 1):
dcmltemp = 2**p
else:
dcmltemp = 0
dcmlValue = dcmlValue + dcmltemp
p = p + 1
tempbinValueNew = tempbinValue
tempbinValueNew = tempbinValueNew >> p
print('%d' % dcmltemp)
print('%.4f' % dcmlValue)[/color]
GPIO.cleanup()