Sensor readings (where black strip is located) Center Left Center C:\Code\Python\readOptical\src>python readoptical.py sensor _in = 0xff action1 = 0x0 action2 = 0x0 sensorValue1 = 0x0 sensorValue2 = 0x0 0xff & 0xf00 0xff = 0b0000000011111111 0xf00 = 0b0000111100000000 if 0xff & 0xf00 == 0 inside if sensor_in & 0xf00 == 0 0xff & 0xff sensorValue1 = 0b0000000011111111 & 0b0000000011111111 ------------------ 0b0000000011111111 sensorValue1 = 0xff inside of sensorValue1 == 0xff 0x0 | 0x01 action1 = 0b0000000000000000 | 0b0000000000000001 ------------------ 0b0000000000000001 action1 = 0x1 inside of sensorValue2 == 0x00 0x1 | 0x02 action1 = 0b0000000000000001 | 0b0000000000000010 ------------------ 0b0000000000000011 action1 = 0x3 go forward sensor _in = 0x100 action1 = 0x3 action2 = 0x3 sensorValue1 = 0xff sensorValue2 = 0x0 0x100 & 0xf00 0x100 = 0b0000000100000000 0xf00 = 0b0000111100000000 if 0x100 & 0xf00 == 0 inside elif 0x100 & 0xff sensorValue2 = 0b0000000100000000 & 0b0000000011111111 ------------------ 0b0000000000000000 SensorValue2 = 0x0 inside of sensorValue1 == 0xff 0x3 | 0x01 action1 = 0b0000000000000011 | 0b0000000000000001 ------------------ 0b0000000000000011 action1 = 0x3 inside of sensorValue2 == 0x00 0x3 | 0x02 action1 = 0b0000000000000011 | 0b0000000000000010 ------------------ 0b0000000000000011 action1 = 0x3 sensor _in = 0x0 action1 = 0x3 action2 = 0x3 sensorValue1 = 0xff sensorValue2 = 0x0 0x0 & 0xf00 0x0 = 0b0000000000000000 0xf00 = 0b0000111100000000 if 0x0 & 0xf00 == 0 inside if sensor_in & 0xf00 == 0 0x0 & 0xff sensorValue1 = 0b0000000000000000 & 0b0000000011111111 ------------------ 0b0000000000000000 sensorValue1 = 0x0 inside sensorValue1 == 0x00 0x3 & 0xfe action1 = 0b0000000000000011 & 0b0000000011111110 ------------------ 0b0000000000000010 action1 = 0x2 inside of sensorValue2 == 0x00 0x2 | 0x02 action1 = 0b0000000000000010 | 0b0000000000000010 ------------------ 0b0000000000000010 action1 = 0x2 turn right sensor _in = 0x100 action1 = 0x2 action2 = 0x2 sensorValue1 = 0x0 sensorValue2 = 0x0 0x100 & 0xf00 0x100 = 0b0000000100000000 0xf00 = 0b0000111100000000 if 0x100 & 0xf00 == 0 inside elif 0x100 & 0xff sensorValue2 = 0b0000000100000000 & 0b0000000011111111 ------------------ 0b0000000000000000 SensorValue2 = 0x0 inside sensorValue1 == 0x00 0x2 & 0xfe action1 = 0b0000000000000010 & 0b0000000011111110 ------------------ 0b0000000000000010 action1 = 0x2 inside of sensorValue2 == 0x00 0x2 | 0x02 action1 = 0b0000000000000010 | 0b0000000000000010 ------------------ 0b0000000000000010 action1 = 0x2 sensor _in = 0xff action1 = 0x2 action2 = 0x2 sensorValue1 = 0x0 sensorValue2 = 0x0 0xff & 0xf00 0xff = 0b0000000011111111 0xf00 = 0b0000111100000000 if 0xff & 0xf00 == 0 inside if sensor_in & 0xf00 == 0 0xff & 0xff sensorValue1 = 0b0000000011111111 & 0b0000000011111111 ------------------ 0b0000000011111111 sensorValue1 = 0xff inside of sensorValue1 == 0xff 0x2 | 0x01 action1 = 0b0000000000000010 | 0b0000000000000001 ------------------ 0b0000000000000011 action1 = 0x3 inside of sensorValue2 == 0x00 0x3 | 0x02 action1 = 0b0000000000000011 | 0b0000000000000010 ------------------ 0b0000000000000011 action1 = 0x3 go forward sensor _in = 0x100 action1 = 0x3 action2 = 0x3 sensorValue1 = 0xff sensorValue2 = 0x0 0x100 & 0xf00 0x100 = 0b0000000100000000 0xf00 = 0b0000111100000000 if 0x100 & 0xf00 == 0 inside elif 0x100 & 0xff sensorValue2 = 0b0000000100000000 & 0b0000000011111111 ------------------ 0b0000000000000000 SensorValue2 = 0x0 inside of sensorValue1 == 0xff 0x3 | 0x01 action1 = 0b0000000000000011 | 0b0000000000000001 ------------------ 0b0000000000000011 action1 = 0x3 inside of sensorValue2 == 0x00 0x3 | 0x02 action1 = 0b0000000000000011 | 0b0000000000000010 ------------------ 0b0000000000000011 action1 = 0x3 C:\Code\Python\readOptical\src>