Hello!
I have received help elsewhere about this obstacle but unfortunately itās going over my head at the moment. Notā¦way over, about an inch, but, still - itās going over my head. Iām pretty good at āadaptingā code, and adding to existing code, Iāve cooked up reasonably involved projects before on the Arduino platform, but I am not an experienced coder at all so would really welcome some help turning advice/help into actual code. I donāt want to pester ScruffR anymore - who has been helpful and patient. Hence this new thread.
Background (skip if youāre not interested!)
Basically I am trying to create something like the VoicePage checkout system for the small āmom and popā shop I work in. There are two checkouts, an office and a little workshop. It would be SO useful to send messages between these places with buttons and LEDs rather than picking up the internal telephone all the time. I had thought to do this with spark.subscribe/spark.publish and four particle cores. I got so excited when I saw the spark core (as was) being talked about online - it all sounded like it would be easy for someone who had been able to cobble arduino projects together by writing the odd bit of code but mainly patching in bits of code or adapting code examples. Especially as all Iām really doing is flicking LEDs/relays etc on and off in response to inputs. Things Iāve easily been able to do with the Arduino. It sounded like the Spark platform would enable me to do that but with a small family of devices due to its cloud based nature. However the more into the project I have got the more limitations/restrictions/bugs I have found which need to be overcome with programming nouse I donāt yet(?) have! Things like adding a heartbeat to a particle project to overcome the bug (now fixed, it seems!) whereby if the particle dropped its WiFi connection, which mine seem to do a lot, it didnāt automatically resubscribe. All concepts I can understand, and no problem for a real programmer, but an insurmountable hurdle for me so far. Iām also not complaining, merely explaining my difficulty.
So, my issue:-
I have code which is āadaptedā from Quantumly Entangled LEDs and itās working. I can make two separate digital pins go high or low on a particle core based on inputs on another particle core being pressed using spark subscribe and spark publish. Iāve been given some advice about how to adapt/extend this code but it is just a bit too abstract for me. Does anyone have time to hold my hand?
Code for Core I Code for Core II
This is the advice I have been given:-
If you wrap your sending device ID and any other useful info into your event name and data payload you can just get along with one handler.
There might me some doc reading to be done, but one hint is that the event name you are subscribing to is only a prefix filter (e.g. CoreToggle would fire for CoreToggle1 and CoreToggle2 and even CoreToggleAnyOtherSuffix).
Just check the contents of toggle along side onOff.
If you use your DeviceID rather than an arbitrary number you can even flash the same code to all of your Cores and each Core would know if itās receiving own events or one of the others without the need to set that number in code for each individual Core. [ā¦]
when you subscribe to e.g. āmyPrefixā your handler will be triggered for anything that starts with āmyPrefixā, so you can use do e.g. Particle.publish(āmyPrefixLED1ā, āONā) and Particle.publish(āmyPrefixLED2ā, āOFFā) and both wil trigger the same handler. To check which LED is meant, you look at the first parameter you called *toggle.
Or you send something like āLED1=OFFā/LED2=ON", split this up and use the seperated values.
So as I say, I can understand this in principle, I just canāt turn it into code. I would be happy to be pointed in the direction of a code example, and no doubt(!) Iāll be able to strip it for parts and make it work for my situation. But I canāt find one online and I canāt write one from where I am now. Which is my failing.
The other thing is, I am a bit at sea re: button debouncing. The button debouncing in my above code examples on pastebin work a treat, but they mean introducing lots of new variables each time I add a button. Is there a library that will handle debouncing for me? Any recommendation there?
THANKS for your help in advance, much appreciated.