Skip to content

Conversation

@mutesplash
Copy link
Contributor

Also indicate which LED each value illuminates

Reverse was being called in the class initialization which wrote it out to the serial port, however, it didn't seem to "stick" unless the port was turned on first and prevented the LEDs from functioning.

Also indicate which LED each value illuminates

Reverse was being called in the class initialization which wrote it out to the serial port, however, it didn't seem to "stick" unless the port was turned on first and prevented the LEDs from functioning.
@chrisruk
Copy link
Contributor

Hi, thanks for the pull req., but currently I can't replicate a problem with the LEDs, I'm using the following code:

from buildhat import DistanceSensor
from signal import pause

d = DistanceSensor('D')
print(d.get())
d.eyes(100,0,100,0)
pause()

@mutesplash
Copy link
Contributor Author

As soon as you use DistanceSensor.on(), the "set -1" serial command that is sent to initialize the port is cleared out and never reset. If you put

d.on()
d.off()

anywhere before "d.eyes()" it won't work anymore. If you enclose the eyes() call within an on() off() series of calls, it won't work either. I've had it work once while testing permutations of this, but it seems like a race condition. Subsequent runs of the program don't work without the patch.

@mutesplash
Copy link
Contributor Author

Alright, if you put d.get() above an on()/off() toggle, it will work. Also, get() is part of the device base class. Why should this be called to initialize it?

@chrisruk
Copy link
Contributor

chrisruk commented Dec 14, 2021

Sorry I think I misunderstood what you where doing before, normally you shouldn't have to use the .on(),.off(),.reverse() functions directly for this class.

I've just overrode .on() now for the distance sensor so that it sends set -1. It shouldn't call

super().on()

though too, as that would send 'set 1' also.

The sensor calls 'set -1' too in the init function, so that .get() etc. calls function correctly.

Both the distance sensor and the color sensor need 'set -1' to function correctly.

@mutesplash
Copy link
Contributor Author

I tested it out and it seemed to work great. Can we still add some documentation to the order of the LED parameters?

@chrisruk chrisruk merged commit 410ab37 into RaspberryPiFoundation:main Dec 21, 2021
@mutesplash mutesplash deleted the patch-1 branch December 22, 2021 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants