Indents are very important in Python. Its how sections of code are grouped and linked together.
Its one very annoying aspect of Python and something that is very hard to wrap your head around.
Those in the know will say use the tab key not the space key to set your indents.
Also I think you need some spaces in there between the if state
if state == 'forward':
eh.motor.onebackwards(100)
eh.motor.twoforwards(100)
if state == 'back':
eh.motor.oneforwards(100)
eh.motor.twobackwards(100)
if state == 'left':
eh.motor.twostop()
eh.motor.onebackwards(100)
etc
When using somebody else’s code and or code from the Internet, try to keep the original formatting as much as possible. I’d clip and past it directly into your editor. If you save it as a text file its likely going to lose the formatting and give you headaches latter on.
Thank you ! I am going to check the whole code. I put spaces as you said. I saved the code directly in python from internet : it is supposed to be the same.
Do you think that the problem could came from the version of my raspberry ? (it is raspberry pi 2). It should work but I want to be sure it is not the source of the problem.
I don’t think the version of the Pi is the issue. The GPIO layout and the way it works is the same on every Pi with the 40 pin GPIO header. I’m running my Rover code on a Zero W and Explorer pHat.
I have had some python code error when run in python 3 but was fine when run in python 2. Usually because the software used with it was installed for python 2 but not 3.
okay thank you very much for this information.