I am very new to programming but not new to electronics. I am wondering if I can find some help here.
I want to communicate between my two Photons. I would like to connect five push buttons to each Photon and five LEDs. When a push button is pressed on one Photon I would like a corresponding LED on the other Photon to light. When the button is pressed again the LED should go off.
How would I best achieve this? I have seen Quantumly Entangled LEDs but because I want to control ten LEDs using ten push buttons I think I exceed the Particle limit for Subscribe/Publish.
I have a feeling what I want to do is achievable using just TWO (or even one?) Subscribe / Publish functions but I lack the programming nous to do this. I have seen reference here on this forum to there being some ability using a prefix filter to possibly work around this using a subscription handler but again, I sadly don’t understand how I would do this
A pointer (ideally in simple/long winded code) would be awesome.
You could probably use a single publish to transmit the state of all buttons at once. If you ‘encode’ it in a binary string, you could have a series of 0/1 represent the states of the buttons/leds. 00100 would be the third LED on, for example.
How often do you expect to hit those buttons?
Not that often - I plan to have one in my sister’s house and one in mine, and to use it as a sort of fun message telegraphing system.
encoding as binary string etc sounds good, but it’s the doing that that’s eluding me I guess!
So would each Photon subscribe to the publish of the other Photon ? And those Publish would be distinct from each other?
That’s the most interesting part, trying to come up with ways to solve that There’s more than one way to do this, my suggestion was just one of many. You could also send it on a per-button case; when you hit button three, send “30” or “31”, for 3 on or off, respectively. You could do it with text as well, or even entirely different publishes, while using a common prefix.
Essentially, yes. If you’re planning on using a single publish/subscribe, you’d need a way to identify which publish came from which device. The easier way would be to use two different publishes:“device 1/device 2”, and subscribe accordingly.
We usually try enabling people by gently nudging them in the “right” direction with verbal instructions and targeted questions - just as @Moors7 has done already.
But as it happens a while back I assisted another member with a project that went a similar way. So as it happens I’ve still got that code and would provide you with a link if you make sure to actually look at the code and try to understand why and how it works.
Meanwhile I’ll try to dig up the respective thread for your to also follow the reasoning provided there.
Thanks you @ScruffR and @Moors7
You may find several threads that feature references to my code by searching the forum for COMMON_DEVICE_NAME_PREFIX
Thanks @ScruffR, is that how I should try to find the code you mentioned? That’s fine, of course, if that’s what you intend!
I think this is the most relevant thread Help with spark.publish / spark.subscribe, please?
Although nowadays I’d rather use
particle instead of
spark and over time other member requests have lead to some additional features in that sketch like here
And as this was an evolving project, following the reasoning provided in the blurb might be a way to find into the why/how.