Back to Parent

Process 

We knew that we wanted to create something simple and do it well, so when it came to our design, we were mindful of both the form, behavior, and code being manageable for us. We built our code piece by piece as follows, almost as coding exercises that built on top of each other:

1. Step 1: Connect one neopixel each on two particle boards

The exercise on connecting two servo motors was helpful for this and gave us an easy starting point. However, in the beginning, we were using particle.function to trigger turning on the neopixels through the console. This worked well for the neopixel that was directly connected to the same computer but not the one listening through particle.subscribe. In trying to debug this code we learned that that was happening because particle.function is suited for simple operations (like math, assignments, etc). We fixed this issue through the second step.

2. Step 2: Connecting the photoresistor

We wanted to utilize the gesture of placing and removing the phone on the device to indicate distraction. When the device is removed, the light would breathe (slow ambient blinking) instead of staying consistent. We considered two sensors for this: the pressure sensor and the photoresistor. The pressure sensor is not very sensitive to weight and would have led to errors so we decided to use the photoresistor, such that light falling on the photoresistor would indicate distraction. This decision helped us not only with the behavior we wanted to achieve, but also solved our first issue. We could just use the thresholds for different intensities of light falling on the photoresistor for if-else statements, without needing the console or a push button to do the first step.

3. Adding the second neopixel, pretty straightforward

4. Connecting the two devices through particle.subscribe

This step took us a while to crack. Both devices had the same wiring and the code, but each photoresistor was supposed to control the behavior of a specific neopixel (either D2 or D3) but on both devices. Somewhere we had to utilize the device ID (not the token) to do this so that the handler code for particle.subscribe could use this information. We eventually figured out that this needed to be a part of our published event and wrote if-else statements that linked to two different device ids, but still kept getting an error wherein both the photoresistors were controlling all neopixels without any differentiation. Getting a second set of eyes on the code revealed a simple mistake that we had used = instead of == in the handler code which was causing the conditional statement in our code to pass.

5. Running out of data limit:

Soon after we got the code working, the particle devices we were using ran out of their data limit and we had to configure two other devices to do the same thing. We got stuck on this but our class TA helped us do this step by step through particle CLI which fixed the issue.


Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0