![]() When you remove your finger, the event says that the beam is now intact. As you put your finger in front of the beam, you'll see an event appear that says the beam was broken. You can check out the results on your console at. If you mess up, don't worry- you can just hit "reset" on your device and do it again! Put your finger in the beam when the D7 LED goes on, and hold it in the beam until you see two flashes from the D7 LED. Basically, a tripwire!įor your convenience, we've set up a little calibrate function so that your device will work no matter how bright your LED is, or how bright the ambient light may be. Every time the beam is broken or reconnected, your device will send a Particle.publish to the cloud letting it know the state of the beam. In this example, we've created a system where you turn your LED and photo sensor to face each other, making a beam of light that can be broken by the motion of your finger. We're allowed to name that event, set the privacy of that event, and add a little bit of info to go along with the event. Particle.publish sends a message to the cloud saying that some event has occurred. What if we simply want to know that something has happened, without all the information of a variable or all the action of a function? We might have a security system that tells us, "motion was detected!" or a smart washing machine that tells us "your laundry is done!" In that case, we might want to use Particle.publish. Make a motion detector: publish and the console Intro Now you can turn your LED on and off and see the values at A0 change based on the phototransistor or photoresistor! Particle variable get device_name analogvalueĪnd make sure you replace device_name with either your device ID or the casual nickname you made for your device when you set it up. You can also check out this value by using the command line. (Be sure to replace your-device-ID-goes-here with your actual device ID and your-access-token-goes-here with your actual access token!) You can see a JSON output of your Particle.variable() call by going to: ![]() Pin an an OUTPUT instead of digital input. The setup() function is called once when the device boots to, well, set up the device. If you leave this out, your code won't run (and the LED will not blink) until you've connected to the network and the ParticleĬloud successfully (breathing cyan). You mostly just need to know if you add this line, your code will run immediately at startup, before connecting to the cloud. You can learn more about threading in the firmware API reference, but for now You could change the constant in this one place at the top of the file. If you wanted to use an external LED connected to D2, for example, This defines which pin we want to blink, in this case D7. This code has a lot of comments, but a few things to note:
0 Comments
Leave a Reply. |