pheriperal indexing start from O || 1
Posted: Fri May 09, 2014 1:18 pm
Hi,
I played around a bit with the new micropython boards. Nice ... REALLY NICE! Congrats to everyone who was involved.
Just noticed a little glitch. Shouldn't we start to count peripherals starting from 0?
This is how python does indexing and I believe it would be more "in-line" doing the same for peripherals.
Thus, one can do:
or
It starts to become more obvious if you start to mix python lists with peripherals addressing.
I believe the i+1 thing will be a trap for a lot of people.
Sure you could get around this by using dictionaries or some other (smarter) way to deal with it. However, since micropython novice might be python beginners too, I wonder if we should try avoid this situation?
It is only a small difference and maybe you find it completely unimportant. We are just at the beginning and hence can still change this (not much live threaten code is written yet)
If there is an argument for doing it vice versa, I would love to hear that
I played around a bit with the new micropython boards. Nice ... REALLY NICE! Congrats to everyone who was involved.
Just noticed a little glitch. Shouldn't we start to count peripherals starting from 0?
This is how python does indexing and I believe it would be more "in-line" doing the same for peripherals.
Thus, one can do:
Code: Select all
for i in range(4):
pyb.LED(i).off()
Code: Select all
leds = [pyb.LED(i) for i in range(4)]
Code: Select all
feedback = ['blue','red','orange','green']
for i in range(4):
print(text[i])
pyb.LED(i+1).on()
Sure you could get around this by using dictionaries or some other (smarter) way to deal with it. However, since micropython novice might be python beginners too, I wonder if we should try avoid this situation?
It is only a small difference and maybe you find it completely unimportant. We are just at the beginning and hence can still change this (not much live threaten code is written yet)
If there is an argument for doing it vice versa, I would love to hear that
