The goal of our final project was to integrate our electrical, mechanical, and design skills we have been learning throughout the semester in order to create an assistive device for an older person. This assistive device was intended to address any problem in our older friend, Elinor’s, life. After meeting Elinor and having conversations with her, we realised that she enjoyed a really active, fast-paced lifestyle and was not encountering any specific problems. Based on our talks, we were inspired by her crazy packed schedule and the lack of time that she takes just for herself to relax, even if just for a minute. We decided to create a device that will help Elinor to take breaks during her busy schedule and take a minute to breathe even when she’s on-the-go. Our device uses a heart rate sensor and an LED ring to visualise Elinor’s heart rate through a pulsing light, which guides her through a series of deep breaths for a minute. We also created a home dock/charging port for her portable device that will recharge it, and also contain more breathing exercises on an LCD display. Continue reading this post to learn more about our device, and our entire process of how we got here!

Read more about earlier stages in our project:

First meeting/ideation: https://courses.ideate.cmu.edu/60-223/s2019/work/interview-with-elinor/

First prototype: https://courses.ideate.cmu.edu/60-223/s2019/work/team-elinor-prototype-documentation/

What We Built

The “puck” is compact enough to be carried wherever Elinor goes and was designed with her hand size in mind.

A sequence of blue pulses guides the rate of deep breathing.

The ring of lights turns green to signal the end of a minute of deep breathing.

Inspired by smooth river stones, the puck was designed to be smooth and rounded for great ergonomics.

As the portable puck charges in the cable, a display guides Elinor through more mindfulness exercises.

The puck and dock were designed together to be approachable and small enough to be placed on a nightstand or desk.

Fitting all the necessary components inside both enclosures proved a challenge, but was possible through careful modeling and prototyping.

The puck measures about an inch and a half in height, meaning that the many parts inside had to be stacked and arranged carefully.

A pair of copper contacts on the dock provide omnidirectional charging to the battery inside the puck.

Two concentric rings surround the capacitive touch sensor. When Elinor returns home, she can simply drop the puck on the dock to start charging – no need to align contacts or plug in a cable.

The puck charging on the dock.

Here’s how we imagine Elinor using our device:

Elinor wakes up in the morning and opens her calendar app on her phone to familiarise herself with the agenda for the day. The first thing she needs to do is drop her daughter off at school. Before leaving, she takes her mindfulness device with her and drops it in her bag.

After dropping her daughter off, she goes straight to a meeting and then to the grocery store. By the time she finishes grocery shopping, Elinor is feeling exhausted and has 5 minutes to spare before she needs to go back home. She takes out her mindfulness device and completes some deep breathing for 2 minutes while playing calming music on her meditative playlist, and feels so much more relaxed than she did before. She’s ready to go back home and tackle the rest of her day!

When she gets home, she decides she wants to do a few more breathing exercises. She sits at her desk where the dock for her mindfulness device is, and reads the instructions on the screen for 5 more minutes. Before going to sleep, she drops her mindfulness device in the dock that stays on her desk and it starts charging so it’s ready for her to use tomorrow.

When Elinor drops the puck onto the dock to charge, the display welcome her home and guides her through an optional meditation exercise.

How We Got Here

On the day of our final presentation and critique, we were really proud of how everything came together into a working device. Our last prototype is miles away from how our first prototype looked, and incorporated feedback from Elinor regarding features she wanted to see in our device as well as how she wanted it to look and feel.

Starting to work on what our device would look like

The first 3D print of a solid puck shape. We tested out the size of this one before moving on

One of our first considerations was the form factor of our portable device. Since Elinor will be using this device to help her through meditative exercises and to relax, it was important that the device itself evoked a sense of calmness. We were inspired by shapes like worry stones and organic forms such as a Google home that Elinor could easily hold in one hand while she uses it. We went through several different iterations of the form, starting with a compact puck looking shape and tested out the shape and size with Elinor before landing on the final form.

After testing with elinor’s hand, we landed on a size and also measured out our components to make sure everything fit inside

Notes from our consultation with Elinor after our first prototype

Elinor also provided a lot of inspiration for what types of features she wanted to see in our device. In the beginning, we intended on having an LED ring to visualise her heart rate through pulsing as well as a vibrating motor to provide haptic feedback. After meetings however, we learned that Elinor was less interested in features such as haptic feedback and was more interested in actually learning breathing/meditation exercises, so we created a playlist with calming sounds and guided breathing exercises as a companion and also added in an LCD screen in the dock that would teach her exercises and worked on building the most functionality in regard to the LED ring– such as changing colors. The pulsing started out with only basic white LEDs that corresponded with her heart rate. Elinor told us that she would love to see a variety of colors and that she would prefer colors other than white, so we used a light purple color for the first 5 seconds of usage while a baseline rate is being set, blue during the actual minute of deep breathing, and green to indicate when a minute has passed and the heart rate sensor turns off. We considered what types of colors would be most calming– we started out having red as the indication that a minute has passed, but decided it was too harsh and changed to red.

The idea for a one-minute timer also came from Elinor, who did not previously meditate or complete any type of breathing exercises during her lifestyle. She also did not want 5 or 10 minute long cycles because those are harder to fit into her schedule. As we hope our device can act as a sort of gateway into bringing more relaxation into her life, each breathing cycle is set at one minute at a time so that it’s something quick that can be done even while she is in her car.

We ran into many challenges along the way in regards to the electronic component of building our device. The heart rate sensor that was available to check out in our lab was a really finicky part and often displayed strange (too high or too low) heart rate readings when we used it (more details about the problems we ran into can be read here). We thought about going a different route and pivoting to use a different part or tackle the issue of mindfulness in a different way but ultimately decided to stick with it and order a new heart rate sensor that would hopefully work better. Fortunately, the new part that we ordered behaved much more normally and although far from medical grade, displayed normal and pretty accurate heart rate readings when compared with an apple watch.

Another issue we ran into was with the wireless data transmission. Initially, one of the features that we wanted to have was wireless data transmission from Elinor’s portable device to the dock that stayed at home to display average BPM and average usage amounts over the course of a day and over the course of a week. We worked really hard on implementing this feature and was able to make it work in the beginning stages, but when we went to put all of the parts together, we discovered that both devices needed to use the same specialised pin (the SPI pin) on the Arduino. We attempted to find workaround solutions and followed tutorials that had the same problem but ultimately was not able to fix the issue and decided to devote the rest of our time to making all of the other components of our final product work properly and look great.

We added in a capacitative sensor that will turn on and off the device so that the heart rate sensor is not constantly measuring

Soldering all of our components together to make them fit into our shell

Making sure everything fits inside!

Working on the contacts to make sure the rechargeable battery works

Working hard to debug and work with the mess of components on the 11th hour!

As most long-term projects go, we were initially able to stick to our schedule and plan as we worked individually on software and hardware. However, as we got closer to final critique day, we realised that fabrication and assembly of our products took much, much longer than we expected. The night before the critique we worked tirelessly to debug, solder, and assemble everything into a functioning beautiful device! The issues that we mentioned were by far our biggest problems but we wanted to make sure to deliver Elinor something that she would really appreciate.

Conclusions and Lessons Learned

At the critique, the positive feedback was largely directed at the form factor of the device and how polished it looked– “The design of the device is lovely. It looks very touchable and smooth.” “Nice design and good calming indicator.” We were really happy that visitors who came by and interacted with our device seemed to feel a sense of calmness from the device itself, which is what we had really hoped and intended for. 

Recurring feedback that we received mostly revolved around if Elinor would actually use our device, and the necessity of it– “It depends on the user to create a habit.” “Doesn’t seem to solve a large problem.” Some future features we would want to add to address this sort of feedback would be to focus on data feedback between the portable device and the dock so that Elinor can take a look back at how many times she has used the device, and if her resting heart beat or average BPM has improved over the course of her usage. This would definitely be implemented in a second iteration of our project. 

 We also considered this “can’t she just use her phone?” factor throughout our design process, and made a conscious decision to keep our device as analog as possible. Elinor uses her digital phone, tablet, and watch very often and we wanted to create something more tactile and interactive that she can integrate into her daily life without feeling a huge sense of foreignness. The functionality exists on other devices, but the way that the features are presented is one of the most important parts.

In a future iteration, we would also definitely add more features for the portable component such as a different time length setting for the device so that Elinor can have 1, 3, 5, 10 minute settings. Some other, more physical features we would focus on if we had more time would be to refabricate the dock using a more sturdy print to make sure that it will stay on her desk without any issues or breakage. 

Working with Elinor was a really unique experience that we had not been able to experience through a class or through any other project. At school we are constantly surrounded by like-minded people who often have similar life experiences. We had a great time visiting Elinor’s house and learning about the different perspectives that she has on life. This project also allowed for us to stretch our minds in terms of designing for her, since the prompt was really open-ended and let us work with an abstract problem like mindfulness.

We did feel a bit of a disadvantage as a two-person team, since one of us almost solely focused on software and the other on hardware. If we had one more person, we feel that we would have been able to add more functionality than we were able to, or spend even more time honing in on the form factor. Despite this, we are really proud of what we were able to create and learned a lot not just about electronics, but about working with people who are different from us! Watching Elinor use our device on final critique day was definitely the highlight of the project.

Schematic:

Code for the portable device:

  1. <span class="com">/*
  2. * Mindfulness Device
  3. *
  4. * Karen Kim + Ian Shei
  5. *
  6. * This code uses a pulse sensor to measure heart rate
  7. * and display it through an LED ring. There are
  8. * different thresholds that determine the speed
  9. * of the pulsing of the LED ring.
  10. *
  11. * Input: heart rate sensor (A0), capacitative sensor (Pin 6)
  12. * Output: LED ring (Pin 5)
  13. *
  14. * Example code used from:
  15. http://pulsesensor.com/pages/pulse-sensor-amped-arduino-v1dot1
  16. Version 1.0 by Mike Barela for Adafruit Industries, Fall 2015
  17. */</span><span class="pln">
  18. </span><span class="com">#include</span><span class="pln"> </span><span class="str"><Adafruit_NeoPixel.h></span><span class="pln"> </span><span class="com">// Library containing</span><span class="pln">
  19. </span><span class="com">#include</span><span class="pln"> </span><span class="str"><SPI.h></span><span class="pln">
  20. </span><span class="com">#include</span><span class="pln"> </span><span class="str"><nRF24L01.h></span><span class="pln">
  21. </span><span class="com">#include</span><span class="pln"> </span><span class="str"><RF24.h></span><span class="pln">
  22. </span><span class="com">#define</span><span class="pln"> CE_PIN </span><span class="lit">9</span><span class="pln">
  23. </span><span class="com">#define</span><span class="pln"> CSN_PIN </span><span class="lit">10</span><span class="pln">
  24. </span><span class="com">// Behavior setting variables</span><span class="pln">
  25. </span><span class="kwd">int</span><span class="pln"> pulsePin </span><span class="pun">=</span><span class="pln"> A0</span><span class="pun">;</span><span class="pln"> </span><span class="com">// Pulse Sensor purple wire connected to analog pin 0</span><span class="pln">
  26. </span><span class="kwd">int</span><span class="pln"> blinkPin </span><span class="pun">=</span><span class="pln"> </span><span class="lit">13</span><span class="pun">;</span><span class="pln"> </span><span class="com">// Digital pin to blink led at each beat</span><span class="pln">
  27. </span><span class="kwd">int</span><span class="pln"> ringPin </span><span class="pun">=</span><span class="pln"> </span><span class="lit">5</span><span class="pun">;</span><span class="pln"> </span><span class="com">// pin to do fancy neopixel effects at each beat</span><span class="pln">
  28. </span><span class="kwd">int</span><span class="pln"> fadeRate </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln"> </span><span class="com">// used to fade LED on with PWM on ringPin</span><span class="pln">
  29. </span><span class="kwd">int</span><span class="pln"> sensorPin </span><span class="pun">=</span><span class="pln"> </span><span class="lit">6</span><span class="pun">;</span><span class="pln">
  30. </span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> motorPin </span><span class="pun">=</span><span class="pln"> </span><span class="lit">3</span><span class="pun">;</span><span class="pln">
  31. </span><span class="com">// array for LED brightness pulsing values </span><span class="pln">
  32. </span><span class="kwd">int</span><span class="pln"> brightnessVal </span><span class="pun">[</span><span class="lit">201</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="pun">{</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">1</span><span class="pun">,</span><span class="pln"> </span><span class="lit">1</span><span class="pun">,</span><span class="pln"> </span><span class="lit">2</span><span class="pun">,</span><span class="pln"> </span><span class="lit">2</span><span class="pun">,</span><span class="pln"> </span><span class="lit">3</span><span class="pun">,</span><span class="pln"> </span><span class="lit">4</span><span class="pun">,</span><span class="pln"> </span><span class="lit">5</span><span class="pun">,</span><span class="pln"> </span><span class="lit">6</span><span class="pun">,</span><span class="pln"> </span><span class="lit">8</span><span class="pun">,</span><span class="pln"> </span><span class="lit">9</span><span class="pun">,</span><span class="pln"> </span><span class="lit">10</span><span class="pun">,</span><span class="pln"> </span><span class="lit">12</span><span class="pun">,</span><span class="pln"> </span><span class="lit">14</span><span class="pun">,</span><span class="pln"> </span><span class="lit">16</span><span class="pun">,</span><span class="pln"> </span><span class="lit">18</span><span class="pun">,</span><span class="pln"> </span><span class="lit">20</span><span class="pun">,</span><span class="pln"> </span><span class="lit">22</span><span class="pun">,</span><span class="pln"> </span><span class="lit">24</span><span class="pun">,</span><span class="pln"> </span><span class="lit">27</span><span class="pun">,</span><span class="pln"> </span><span class="lit">29</span><span class="pun">,</span><span class="pln"> </span><span class="lit">32</span><span class="pun">,</span><span class="pln"> </span><span class="lit">35</span><span class="pun">,</span><span class="pln"> </span><span class="lit">37</span><span class="pun">,</span><span class="pln"> </span><span class="lit">40</span><span class="pun">,</span><span class="pln"> </span><span class="lit">43</span><span class="pun">,</span><span class="pln"> </span><span class="lit">46</span><span class="pun">,</span><span class="pln"> </span><span class="lit">49</span><span class="pun">,</span><span class="pln"> </span><span class="lit">53</span><span class="pun">,</span><span class="pln"> </span><span class="lit">56</span><span class="pun">,</span><span class="pln"> </span><span class="lit">59</span><span class="pun">,</span><span class="pln"> </span><span class="lit">63</span><span class="pun">,</span><span class="pln"> </span><span class="lit">66</span><span class="pun">,</span><span class="pln"> </span><span class="lit">70</span><span class="pun">,</span><span class="pln"> </span><span class="lit">73</span><span class="pun">,</span><span class="pln"> </span><span class="lit">77</span><span class="pun">,</span><span class="pln"> </span><span class="lit">81</span><span class="pun">,</span><span class="pln"> </span><span class="lit">84</span><span class="pun">,</span><span class="pln"> </span><span class="lit">88</span><span class="pun">,</span><span class="pln"> </span><span class="lit">92</span><span class="pun">,</span><span class="pln"> </span><span class="lit">96</span><span class="pun">,</span><span class="pln"> </span><span class="lit">100</span><span class="pun">,</span><span class="pln"> </span><span class="lit">104</span><span class="pun">,</span><span class="pln"> </span><span class="lit">108</span><span class="pun">,</span><span class="pln"> </span><span class="lit">112</span><span class="pun">,</span><span class="pln"> </span><span class="lit">116</span><span class="pun">,</span><span class="pln"> </span><span class="lit">119</span><span class="pun">,</span><span class="pln"> </span><span class="lit">123</span><span class="pun">,</span><span class="pln"> </span><span class="lit">128</span><span class="pun">,</span><span class="pln"> </span><span class="lit">132</span><span class="pun">,</span><span class="pln"> </span><span class="lit">136</span><span class="pun">,</span><span class="pln"> </span><span class="lit">139</span><span class="pun">,</span><span class="pln"> </span><span class="lit">143</span><span class="pun">,</span><span class="pln"> </span><span class="lit">147</span><span class="pun">,</span><span class="pln"> </span><span class="lit">151</span><span class="pun">,</span><span class="pln"> </span><span class="lit">155</span><span class="pun">,</span><span class="pln"> </span><span class="lit">159</span><span class="pun">,</span><span class="pln"> </span><span class="lit">163</span><span class="pun">,</span><span class="pln"> </span><span class="lit">167</span><span class="pun">,</span><span class="pln"> </span><span class="lit">171</span><span class="pun">,</span><span class="pln"> </span><span class="lit">174</span><span class="pun">,</span><span class="pln"> </span><span class="lit">178</span><span class="pun">,</span><span class="pln"> </span><span class="lit">182</span><span class="pun">,</span><span class="pln"> </span><span class="lit">185</span><span class="pun">,</span><span class="pln"> </span><span class="lit">189</span><span class="pun">,</span><span class="pln"> </span><span class="lit">192</span><span class="pun">,</span><span class="pln"> </span><span class="lit">196</span><span class="pun">,</span><span class="pln"> </span><span class="lit">199</span><span class="pun">,</span><span class="pln"> </span><span class="lit">202</span><span class="pun">,</span><span class="pln"> </span><span class="lit">206</span><span class="pun">,</span><span class="pln"> </span><span class="lit">209</span><span class="pun">,</span><span class="pln"> </span><span class="lit">212</span><span class="pun">,</span><span class="pln"> </span><span class="lit">215</span><span class="pun">,</span><span class="pln"> </span><span class="lit">218</span><span class="pun">,</span><span class="pln"> </span><span class="lit">220</span><span class="pun">,</span><span class="pln"> </span><span class="lit">223</span><span class="pun">,</span><span class="pln"> </span><span class="lit">226</span><span class="pun">,</span><span class="pln"> </span><span class="lit">228</span><span class="pun">,</span><span class="pln"> </span><span class="lit">231</span><span class="pun">,</span><span class="pln"> </span><span class="lit">233</span><span class="pun">,</span><span class="pln"> </span><span class="lit">235</span><span class="pun">,</span><span class="pln"> </span><span class="lit">237</span><span class="pun">,</span><span class="pln"> </span><span class="lit">239</span><span class="pun">,</span><span class="pln"> </span><span class="lit">241</span><span class="pun">,</span><span class="pln"> </span><span class="lit">243</span><span class="pun">,</span><span class="pln"> </span><span class="lit">245</span><span class="pun">,</span><span class="pln"> </span><span class="lit">246</span><span class="pun">,</span><span class="pln"> </span><span class="lit">247</span><span class="pun">,</span><span class="pln"> </span><span class="lit">249</span><span class="pun">,</span><span class="pln"> </span><span class="lit">250</span><span class="pun">,</span><span class="pln"> </span><span class="lit">251</span><span class="pun">,</span><span class="pln"> </span><span class="lit">252</span><span class="pun">,</span><span class="pln"> </span><span class="lit">253</span><span class="pun">,</span><span class="pln"> </span><span class="lit">253</span><span class="pun">,</span><span class="pln"> </span><span class="lit">254</span><span class="pun">,</span><span class="pln"> </span><span class="lit">254</span><span class="pun">,</span><span class="pln"> </span><span class="lit">255</span><span class="pun">,</span><span class="pln"> </span><span class="lit">255</span><span class="pun">,</span><span class="pln"> </span><span class="lit">255</span><span class="pun">,</span><span class="pln"> </span><span class="lit">255</span><span class="pun">,</span><span class="pln"> </span><span class="lit">255</span><span class="pun">,</span><span class="pln"> </span><span class="lit">254</span><span class="pun">,</span><span class="pln"> </span><span class="lit">254</span><span class="pun">,</span><span class="pln"> </span><span class="lit">253</span><span class="pun">,</span><span class="pln"> </span><span class="lit">253</span><span class="pun">,</span><span class="pln"> </span><span class="lit">252</span><span class="pun">,</span><span class="pln"> </span><span class="lit">251</span><span class="pun">,</span><span class="pln"> </span><span class="lit">250</span><span class="pun">,</span><span class="pln"> </span><span class="lit">249</span><span class="pun">,</span><span class="pln"> </span><span class="lit">247</span><span class="pun">,</span><span class="pln"> </span><span class="lit">246</span><span class="pun">,</span><span class="pln"> </span><span class="lit">245</span><span class="pun">,</span><span class="pln"> </span><span class="lit">243</span><span class="pun">,</span><span class="pln"> </span><span class="lit">241</span><span class="pun">,</span><span class="pln"> </span><span class="lit">239</span><span class="pun">,</span><span class="pln"> </span><span class="lit">237</span><span class="pun">,</span><span class="pln"> </span><span class="lit">235</span><span class="pun">,</span><span class="pln"> </span><span class="lit">233</span><span class="pun">,</span><span class="pln"> </span><span class="lit">231</span><span class="pun">,</span><span class="pln"> </span><span class="lit">228</span><span class="pun">,</span><span class="pln"> </span><span class="lit">226</span><span class="pun">,</span><span class="pln"> </span><span class="lit">223</span><span class="pun">,</span><span class="pln"> </span><span class="lit">220</span><span class="pun">,</span><span class="pln"> </span><span class="lit">218</span><span class="pun">,</span><span class="pln"> </span><span class="lit">215</span><span class="pun">,</span><span class="pln"> </span><span class="lit">212</span><span class="pun">,</span><span class="pln"> </span><span class="lit">209</span><span class="pun">,</span><span class="pln"> </span><span class="lit">206</span><span class="pun">,</span><span class="pln"> </span><span class="lit">202</span><span class="pun">,</span><span class="pln"> </span><span class="lit">199</span><span class="pun">,</span><span class="pln"> </span><span class="lit">196</span><span class="pun">,</span><span class="pln"> </span><span class="lit">192</span><span class="pun">,</span><span class="pln"> </span><span class="lit">189</span><span class="pun">,</span><span class="pln"> </span><span class="lit">185</span><span class="pun">,</span><span class="pln"> </span><span class="lit">182</span><span class="pun">,</span><span class="pln"> </span><span class="lit">178</span><span class="pun">,</span><span class="pln"> </span><span class="lit">174</span><span class="pun">,</span><span class="pln"> </span><span class="lit">171</span><span class="pun">,</span><span class="pln"> </span><span class="lit">167</span><span class="pun">,</span><span class="pln"> </span><span class="lit">163</span><span class="pun">,</span><span class="pln"> </span><span class="lit">159</span><span class="pun">,</span><span class="pln"> </span><span class="lit">155</span><span class="pun">,</span><span class="pln"> </span><span class="lit">151</span><span class="pun">,</span><span class="pln"> </span><span class="lit">147</span><span class="pun">,</span><span class="pln"> </span><span class="lit">143</span><span class="pun">,</span><span class="pln"> </span><span class="lit">139</span><span class="pun">,</span><span class="pln"> </span><span class="lit">136</span><span class="pun">,</span><span class="pln"> </span><span class="lit">132</span><span class="pun">,</span><span class="pln"> </span><span class="lit">128</span><span class="pun">,</span><span class="pln"> </span><span class="lit">123</span><span class="pun">,</span><span class="pln"> </span><span class="lit">119</span><span class="pun">,</span><span class="pln"> </span><span class="lit">116</span><span class="pun">,</span><span class="pln"> </span><span class="lit">112</span><span class="pun">,</span><span class="pln"> </span><span class="lit">108</span><span class="pun">,</span><span class="pln"> </span><span class="lit">104</span><span class="pun">,</span><span class="pln"> </span><span class="lit">100</span><span class="pun">,</span><span class="pln"> </span><span class="lit">96</span><span class="pun">,</span><span class="pln"> </span><span class="lit">92</span><span class="pun">,</span><span class="pln"> </span><span class="lit">88</span><span class="pun">,</span><span class="pln"> </span><span class="lit">84</span><span class="pun">,</span><span class="pln"> </span><span class="lit">81</span><span class="pun">,</span><span class="pln"> </span><span class="lit">77</span><span class="pun">,</span><span class="pln"> </span><span class="lit">73</span><span class="pun">,</span><span class="pln"> </span><span class="lit">70</span><span class="pun">,</span><span class="pln"> </span><span class="lit">66</span><span class="pun">,</span><span class="pln"> </span><span class="lit">63</span><span class="pun">,</span><span class="pln"> </span><span class="lit">59</span><span class="pun">,</span><span class="pln"> </span><span class="lit">56</span><span class="pun">,</span><span class="pln"> </span><span class="lit">53</span><span class="pun">,</span><span class="pln"> </span><span class="lit">49</span><span class="pun">,</span><span class="pln"> </span><span class="lit">46</span><span class="pun">,</span><span class="pln"> </span><span class="lit">43</span><span class="pun">,</span><span class="pln"> </span><span class="lit">40</span><span class="pun">,</span><span class="pln"> </span><span class="lit">37</span><span class="pun">,</span><span class="pln"> </span><span class="lit">35</span><span class="pun">,</span><span class="pln"> </span><span class="lit">32</span><span class="pun">,</span><span class="pln"> </span><span class="lit">29</span><span class="pun">,</span><span class="pln"> </span><span class="lit">27</span><span class="pun">,</span><span class="pln"> </span><span class="lit">24</span><span class="pun">,</span><span class="pln"> </span><span class="lit">22</span><span class="pun">,</span><span class="pln"> </span><span class="lit">20</span><span class="pun">,</span><span class="pln"> </span><span class="lit">18</span><span class="pun">,</span><span class="pln"> </span><span class="lit">16</span><span class="pun">,</span><span class="pln"> </span><span class="lit">14</span><span class="pun">,</span><span class="pln"> </span><span class="lit">12</span><span class="pun">,</span><span class="pln"> </span><span class="lit">10</span><span class="pun">,</span><span class="pln"> </span><span class="lit">9</span><span class="pun">,</span><span class="pln"> </span><span class="lit">8</span><span class="pun">,</span><span class="pln"> </span><span class="lit">6</span><span class="pun">,</span><span class="pln"> </span><span class="lit">5</span><span class="pun">,</span><span class="pln"> </span><span class="lit">4</span><span class="pun">,</span><span class="pln"> </span><span class="lit">3</span><span class="pun">,</span><span class="pln"> </span><span class="lit">2</span><span class="pun">,</span><span class="pln"> </span><span class="lit">2</span><span class="pun">,</span><span class="pln"> </span><span class="lit">1</span><span class="pun">,</span><span class="pln"> </span><span class="lit">1</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">};</span><span class="pln">
  33. </span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">byte</span><span class="pln"> slaveAddress</span><span class="pun">[</span><span class="lit">5</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="pun">{</span><span class="str">'R'</span><span class="pun">,</span><span class="str">'x'</span><span class="pun">,</span><span class="str">'A'</span><span class="pun">,</span><span class="str">'A'</span><span class="pun">,</span><span class="str">'A'</span><span class="pun">};</span><span class="pln"> </span><span class="com">// for radio </span><span class="pln">
  34. RF24 radio</span><span class="pun">(</span><span class="pln">CE_PIN</span><span class="pun">,</span><span class="pln"> CSN_PIN</span><span class="pun">);</span><span class="pln"> </span><span class="com">// Create a Radio</span><span class="pln">
  35. </span><span class="kwd">char</span><span class="pln"> message</span><span class="pun">[</span><span class="lit">10</span><span class="pun">];</span><span class="pln"> </span><span class="com">// array length for radio message </span><span class="pln">
  36. </span><span class="kwd">char</span><span class="pln"> txNum </span><span class="pun">=</span><span class="pln"> </span><span class="str">'0'</span><span class="pun">;</span><span class="pln">
  37. </span><span class="kwd">unsigned</span><span class="pln"> </span><span class="kwd">long</span><span class="pln"> currentMillis</span><span class="pun">;</span><span class="pln">
  38. </span><span class="kwd">unsigned</span><span class="pln"> </span><span class="kwd">long</span><span class="pln"> prevMillis</span><span class="pun">;</span><span class="pln">
  39. </span><span class="kwd">unsigned</span><span class="pln"> </span><span class="kwd">long</span><span class="pln"> txIntervalMillis </span><span class="pun">=</span><span class="pln"> </span><span class="lit">1000</span><span class="pun">;</span><span class="pln"> </span><span class="com">// send once per second</span><span class="pln">
  40. </span><span class="com">// these variables are volatile because they are used during the interrupt service routine</span><span class="pln">
  41. </span><span class="kwd">volatile</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> BPM</span><span class="pun">;</span><span class="pln"> </span><span class="com">// used to hold the pulse rate</span><span class="pln">
  42. </span><span class="kwd">volatile</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> </span><span class="typ">Signal</span><span class="pun">;</span><span class="pln"> </span><span class="com">// holds the incoming raw data</span><span class="pln">
  43. </span><span class="kwd">volatile</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> IBI </span><span class="pun">=</span><span class="pln"> </span><span class="lit">600</span><span class="pun">;</span><span class="pln"> </span><span class="com">// holds the time between beats, the Inter-Beat Interval</span><span class="pln">
  44. </span><span class="kwd">volatile</span><span class="pln"> </span><span class="kwd">boolean</span><span class="pln"> </span><span class="typ">Pulse</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">;</span><span class="pln"> </span><span class="com">// true when pulse wave is high, false when it's low</span><span class="pln">
  45. </span><span class="kwd">volatile</span><span class="pln"> </span><span class="kwd">boolean</span><span class="pln"> QS </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">;</span><span class="pln"> </span><span class="com">// becomes true when Arduoino finds a beat.</span><span class="pln">
  46. </span><span class="com">// Set up use of NeoPixels</span><span class="pln">
  47. </span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> NUMPIXELS </span><span class="pun">=</span><span class="pln"> </span><span class="lit">24</span><span class="pun">;</span><span class="pln"> </span><span class="com">// Put the number of NeoPixels you are using here</span><span class="pln">
  48. </span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> BRIGHTNESS </span><span class="pun">=</span><span class="pln"> </span><span class="lit">60</span><span class="pun">;</span><span class="pln"> </span><span class="com">// Set brightness of NeoPixels here</span><span class="pln">
  49. </span><span class="typ">Adafruit_NeoPixel</span><span class="pln"> strip </span><span class="pun">=</span><span class="pln"> </span><span class="typ">Adafruit_NeoPixel</span><span class="pun">(</span><span class="lit">24</span><span class="pun">,</span><span class="pln"> ringPin</span><span class="pun">,</span><span class="pln"> NEO_GRBW </span><span class="pun">+</span><span class="pln"> NEO_KHZ800</span><span class="pun">);</span><span class="pln">
  50. </span><span class="kwd">unsigned</span><span class="pln"> </span><span class="kwd">long</span><span class="pln"> startMillis</span><span class="pun">;</span><span class="pln">
  51. </span><span class="kwd">bool</span><span class="pln"> inTrial </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">;</span><span class="pln">
  52. </span><span class="kwd">bool</span><span class="pln"> inWait </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">;</span><span class="pln">
  53. </span><span class="kwd">bool</span><span class="pln"> turnOn </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">;</span><span class="pln">
  54. </span><span class="kwd">int</span><span class="pln"> bpmCount </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
  55. </span><span class="kwd">int</span><span class="pln"> bpmAvg </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
  56. </span><span class="kwd">int</span><span class="pln"> totalBPM </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
  57. </span><span class="kwd">int</span><span class="pln"> dailyBPM</span><span class="pun">[</span><span class="lit">10</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="pun">{-</span><span class="lit">1</span><span class="pun">,-</span><span class="lit">1</span><span class="pun">,-</span><span class="lit">1</span><span class="pun">,-</span><span class="lit">1</span><span class="pun">,-</span><span class="lit">1</span><span class="pun">,-</span><span class="lit">1</span><span class="pun">,-</span><span class="lit">1</span><span class="pun">,-</span><span class="lit">1</span><span class="pun">,-</span><span class="lit">1</span><span class="pun">,-</span><span class="lit">1</span><span class="pun">};</span><span class="pln">
  58. </span><span class="kwd">void</span><span class="pln"> setup</span><span class="pun">(){</span><span class="pln">
  59. pinMode</span><span class="pun">(</span><span class="pln">blinkPin</span><span class="pun">,</span><span class="pln">OUTPUT</span><span class="pun">);</span><span class="pln"> </span><span class="com">// pin that will blink to your heartbeat!</span><span class="pln">
  60. pinMode</span><span class="pun">(</span><span class="pln">motorPin</span><span class="pun">,</span><span class="pln"> OUTPUT</span><span class="pun">);</span><span class="pln">
  61. pinMode</span><span class="pun">(</span><span class="pln">sensorPin</span><span class="pun">,</span><span class="pln"> INPUT</span><span class="pun">);</span><span class="pln">
  62. </span><span class="typ">Serial</span><span class="pun">.</span><span class="kwd">begin</span><span class="pun">(</span><span class="lit">9600</span><span class="pun">);</span><span class="pln"> </span><span class="com">// Serial output data for debugging or external use</span><span class="pln">
  63. strip</span><span class="pun">.</span><span class="kwd">begin</span><span class="pun">();</span><span class="pln">
  64. strip</span><span class="pun">.</span><span class="pln">setBrightness</span><span class="pun">(</span><span class="pln">BRIGHTNESS</span><span class="pun">);</span><span class="pln">
  65. </span><span class="kwd">for</span><span class="pln"> </span><span class="pun">(</span><span class="kwd">int</span><span class="pln"> x</span><span class="pun">=</span><span class="lit">0</span><span class="pun">;</span><span class="pln"> x </span><span class="pun"><</span><span class="pln"> NUMPIXELS</span><span class="pun">;</span><span class="pln"> x</span><span class="pun">++)</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="com">// Initialize all pixels to 'off'</span><span class="pln">
  66. strip</span><span class="pun">.</span><span class="pln">setPixelColor</span><span class="pun">(</span><span class="pln">x</span><span class="pun">,</span><span class="pln"> strip</span><span class="pun">.</span><span class="typ">Color</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">));</span><span class="pln">
  67. </span><span class="pun">}</span><span class="pln">
  68. strip</span><span class="pun">.</span><span class="pln">show</span><span class="pun">();</span><span class="pln"> </span><span class="com">// Ensure the pixels are off</span><span class="pln">
  69. delay</span><span class="pun">(</span><span class="lit">1000</span><span class="pun">);</span><span class="pln"> </span><span class="com">// Wait a second</span><span class="pln">
  70. interruptSetup</span><span class="pun">();</span><span class="pln"> </span><span class="com">// sets up to read Pulse Sensor signal every 2mS</span><span class="pln">
  71. radio</span><span class="pun">.</span><span class="kwd">begin</span><span class="pun">();</span><span class="pln">
  72. radio</span><span class="pun">.</span><span class="pln">setDataRate</span><span class="pun">(</span><span class="pln"> RF24_250KBPS </span><span class="pun">);</span><span class="pln">
  73. radio</span><span class="pun">.</span><span class="pln">setRetries</span><span class="pun">(</span><span class="lit">3</span><span class="pun">,</span><span class="lit">5</span><span class="pun">);</span><span class="pln"> </span><span class="com">// delay, count</span><span class="pln">
  74. radio</span><span class="pun">.</span><span class="pln">openWritingPipe</span><span class="pun">(</span><span class="pln">slaveAddress</span><span class="pun">);</span><span class="pln">
  75. </span><span class="pun">}</span><span class="pln">
  76. </span><span class="kwd">void</span><span class="pln"> loop</span><span class="pun">(){</span><span class="pln">
  77. </span><span class="kwd">int</span><span class="pln"> sensorRead </span><span class="pun">=</span><span class="pln"> digitalRead</span><span class="pun">(</span><span class="pln">sensorPin</span><span class="pun">);</span><span class="pln">
  78. </span><span class="com">// Serial.println(sensorRead);</span><span class="pln">
  79. </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">sensorRead </span><span class="pun">==</span><span class="pln"> HIGH</span><span class="pun">){</span><span class="pln"> </span><span class="com">// use capaacitative sensor to turn on device </span><span class="pln">
  80. turnOn </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">;</span><span class="pln">
  81. </span><span class="pun">}</span><span class="pln">
  82. </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">turnOn </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">){</span><span class="pln">
  83. </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">inWait </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">false</span><span class="pln"> </span><span class="kwd">and</span><span class="pln"> inTrial </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">false</span><span class="pln"> </span><span class="kwd">and</span><span class="pln"> QS </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">){</span><span class="pln"> </span><span class="com">// Quantified Self flag is true when arduino finds a heartbeat</span><span class="pln">
  84. </span><span class="com">// analogWrite(motorPin, 100);</span><span class="pln">
  85. </span><span class="typ">Serial</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"START WAIT"</span><span class="pun">);</span><span class="pln"> </span><span class="com">// setting 5 second baseline for heartrate </span><span class="pln">
  86. inWait </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">;</span><span class="pln">
  87. </span><span class="com">// inTrial = true;</span><span class="pln">
  88. startMillis </span><span class="pun">=</span><span class="pln"> millis</span><span class="pun">();</span><span class="pln">
  89. </span><span class="com">// fadeRate = 255; // Set 'fadeRate' Variable to 255 to fade LED with pulse</span><span class="pln">
  90. </span><span class="typ">Serial</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="pln">BPM</span><span class="pun">);</span><span class="pln">
  91. </span><span class="com">// sendDataSerial('B',BPM); // send heart rate with a 'B' prefix</span><span class="pln">
  92. </span><span class="com">// sendDataSerial('Q',IBI); // send time between beats with a 'Q' prefix</span><span class="pln">
  93. QS </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">;</span><span class="pln"> </span><span class="com">// reset the Quantified Self flag for next time</span><span class="pln">
  94. </span><span class="pun">}</span><span class="pln">
  95. </span><span class="kwd">else</span><span class="pln"> </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">inWait </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">true</span><span class="pln"> </span><span class="kwd">and</span><span class="pln"> millis</span><span class="pun">()</span><span class="pln"> </span><span class="pun">-</span><span class="pln"> startMillis </span><span class="pun">>=</span><span class="pln"> </span><span class="lit">5000</span><span class="pun">){</span><span class="pln">
  96. </span><span class="typ">Serial</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"END WAIT"</span><span class="pun">);</span><span class="pln">
  97. inTrial </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">;</span><span class="pln">
  98. inWait </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">;</span><span class="pln">
  99. startMillis </span><span class="pun">=</span><span class="pln"> millis</span><span class="pun">();</span><span class="pln">
  100. </span><span class="pun">}</span><span class="pln">
  101. </span><span class="kwd">else</span><span class="pln"> </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">inTrial </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">true</span><span class="pln"> </span><span class="kwd">and</span><span class="pln"> QS </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">){</span><span class="pln">
  102. bpmAvg </span><span class="pun">=</span><span class="pln"> totalBPM</span><span class="pun">/</span><span class="pln">bpmCount</span><span class="pun">;</span><span class="pln">
  103. </span><span class="com">// Serial.println(bpmAvg);</span><span class="pln">
  104. </span><span class="typ">Serial</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"IN TRIAL"</span><span class="pun">);</span><span class="pln">
  105. </span><span class="com">// Serial.println(millis() - startMillis);</span><span class="pln">
  106. </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">millis</span><span class="pun">()</span><span class="pln"> </span><span class="pun">-</span><span class="pln"> startMillis </span><span class="pun">>=</span><span class="pln"> </span><span class="lit">5000</span><span class="pun">){</span><span class="pln">
  107. </span><span class="typ">Serial</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"END OF TRIAL"</span><span class="pun">);</span><span class="pln">
  108. inTrial </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">;</span><span class="pln">
  109. </span><span class="kwd">for</span><span class="pln"> </span><span class="pun">(</span><span class="kwd">int</span><span class="pln"> x</span><span class="pun">=</span><span class="lit">0</span><span class="pun">;</span><span class="pln"> x </span><span class="pun"><</span><span class="pln"> NUMPIXELS</span><span class="pun">;</span><span class="pln"> x</span><span class="pun">++)</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="com">// Initialize all pixels to 'off'</span><span class="pln">
  110. strip</span><span class="pun">.</span><span class="pln">setPixelColor</span><span class="pun">(</span><span class="pln">x</span><span class="pun">,</span><span class="pln"> strip</span><span class="pun">.</span><span class="typ">Color</span><span class="pun">(</span><span class="lit">255</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">));</span><span class="pln"> </span><span class="com">// blue light for during 1 minute cycle</span><span class="pln">
  111. </span><span class="pun">}</span><span class="pln">
  112. strip</span><span class="pun">.</span><span class="pln">show</span><span class="pun">();</span><span class="pln">
  113. send</span><span class="pun">(</span><span class="pln">bpmAvg</span><span class="pun">);</span><span class="pln">
  114. totalBPM</span><span class="pun">=</span><span class="lit">0</span><span class="pun">;</span><span class="pln">
  115. bpmCount</span><span class="pun">=</span><span class="lit">0</span><span class="pun">;</span><span class="pln">
  116. delay</span><span class="pun">(</span><span class="lit">1000</span><span class="pun">);</span><span class="pln">
  117. turnOn </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">;</span><span class="pln">
  118. </span><span class="pun">}</span><span class="pln">
  119. </span><span class="com">// fadeRate = 400;</span><span class="pln">
  120. QS </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">;</span><span class="pln">
  121. </span><span class="pun">}</span><span class="pln">
  122. </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">inTrial </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">){</span><span class="pln">
  123. </span><span class="typ">Serial</span><span class="pun">.</span><span class="kwd">print</span><span class="pun">(</span><span class="str">"BPM="</span><span class="pun">);</span><span class="pln">
  124. </span><span class="typ">Serial</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="pln">BPM</span><span class="pun">);</span><span class="pln">
  125. totalBPM</span><span class="pun">+=</span><span class="pln">BPM</span><span class="pun">;</span><span class="pln">
  126. bpmCount</span><span class="pun">+=</span><span class="lit">1</span><span class="pun">;</span><span class="pln">
  127. ledFadeToBeat</span><span class="pun">(</span><span class="pln">BPM</span><span class="pun">);</span><span class="pln"> </span><span class="com">// Routine that fades color intensity to the beat</span><span class="pln">
  128. </span><span class="pun">}</span><span class="pln">
  129. </span><span class="kwd">else</span><span class="pln"> </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">inWait </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  130. </span><span class="kwd">for</span><span class="pln"> </span><span class="pun">(</span><span class="kwd">int</span><span class="pln"> x</span><span class="pun">=</span><span class="lit">0</span><span class="pun">;</span><span class="pln"> x </span><span class="pun"><</span><span class="pln"> NUMPIXELS</span><span class="pun">;</span><span class="pln"> x</span><span class="pun">++)</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="com">// Initialize all pixels to 'off'</span><span class="pln">
  131. strip</span><span class="pun">.</span><span class="pln">setPixelColor</span><span class="pun">(</span><span class="pln">x</span><span class="pun">,</span><span class="pln"> strip</span><span class="pun">.</span><span class="typ">Color</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">255</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">));</span><span class="pln"> </span><span class="com">// turns off after 1 minute</span><span class="pln">
  132. </span><span class="pun">}</span><span class="pln">
  133. strip</span><span class="pun">.</span><span class="pln">show</span><span class="pun">();</span><span class="pln">
  134. </span><span class="pun">}</span><span class="pln">
  135. </span><span class="kwd">else</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  136. setStrip</span><span class="pun">(</span><span class="lit">255</span><span class="pun">,</span><span class="lit">0</span><span class="pun">,</span><span class="lit">0</span><span class="pun">,</span><span class="pln">BPM</span><span class="pun">);</span><span class="pln">
  137. delay</span><span class="pun">(</span><span class="lit">3000</span><span class="pun">);</span><span class="pln">
  138. </span><span class="pun">}</span><span class="pln">
  139. delay</span><span class="pun">(</span><span class="lit">100</span><span class="pun">);</span><span class="pln"> </span><span class="com">// take a break</span><span class="pln">
  140. </span><span class="pun">}</span><span class="pln">
  141. </span><span class="pun">}</span><span class="pln">
  142. </span><span class="kwd">void</span><span class="pln"> ledFadeToBeat</span><span class="pun">(</span><span class="kwd">int</span><span class="pln"> BPM</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  143. </span><span class="kwd">static</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> i </span><span class="pun">=</span><span class="pln"> </span><span class="lit">100</span><span class="pun">;</span><span class="pln">
  144. </span><span class="com">// Set LED fade value</span><span class="pln">
  145. </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">BPM </span><span class="pun"><</span><span class="pln"> </span><span class="lit">50</span><span class="pun">){</span><span class="pln">
  146. i</span><span class="pun">+=</span><span class="lit">1</span><span class="pun">;</span><span class="pln">
  147. </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">i </span><span class="pun">>=</span><span class="pln"> </span><span class="lit">201</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  148. i </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
  149. </span><span class="pun">}</span><span class="pln">
  150. fadeRate </span><span class="pun">=</span><span class="pln"> brightnessVal</span><span class="pun">[</span><span class="pln">i</span><span class="pun">];</span><span class="pln">
  151. fadeRate </span><span class="pun">=</span><span class="pln"> constrain</span><span class="pun">(</span><span class="pln">fadeRate</span><span class="pun">,</span><span class="lit">0</span><span class="pun">,</span><span class="lit">255</span><span class="pun">);</span><span class="pln"> </span><span class="com">// Keep LED fade value from going into negative numbers</span><span class="pln">
  152. setStrip</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="lit">0</span><span class="pun">,</span><span class="pln">fadeRate</span><span class="pun">,</span><span class="pln"> BPM</span><span class="pun">);</span><span class="pln">
  153. </span><span class="pun">}</span><span class="pln">
  154. </span><span class="kwd">else</span><span class="pln"> </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">BPM </span><span class="pun">>=</span><span class="pln"> </span><span class="lit">50</span><span class="pln"> </span><span class="kwd">and</span><span class="pln"> BPM </span><span class="pun"><</span><span class="pln"> </span><span class="lit">80</span><span class="pun">){</span><span class="pln"> </span><span class="com">// setting BPM thresholds to set pulsing speed </span><span class="pln">
  155. i</span><span class="pun">+=</span><span class="lit">2</span><span class="pun">;</span><span class="pln">
  156. </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">i </span><span class="pun">>=</span><span class="pln"> </span><span class="lit">201</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  157. i </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
  158. </span><span class="pun">}</span><span class="pln">
  159. fadeRate </span><span class="pun">=</span><span class="pln"> brightnessVal</span><span class="pun">[</span><span class="pln">i</span><span class="pun">];</span><span class="pln">
  160. fadeRate </span><span class="pun">=</span><span class="pln"> constrain</span><span class="pun">(</span><span class="pln">fadeRate</span><span class="pun">,</span><span class="lit">0</span><span class="pun">,</span><span class="lit">255</span><span class="pun">);</span><span class="pln"> </span><span class="com">// Keep LED fade value from going into negative numbers</span><span class="pln">
  161. setStrip</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="lit">0</span><span class="pun">,</span><span class="pln">fadeRate</span><span class="pun">,</span><span class="pln"> BPM</span><span class="pun">);</span><span class="pln">
  162. </span><span class="pun">}</span><span class="pln">
  163. </span><span class="kwd">else</span><span class="pln"> </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">BPM </span><span class="pun">>=</span><span class="pln"> </span><span class="lit">80</span><span class="pln"> </span><span class="kwd">and</span><span class="pln"> BPM </span><span class="pun"><</span><span class="pln"> </span><span class="lit">100</span><span class="pun">){</span><span class="pln">
  164. i</span><span class="pun">+=</span><span class="lit">3</span><span class="pun">;</span><span class="pln">
  165. </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">i </span><span class="pun">>=</span><span class="pln"> </span><span class="lit">201</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  166. i </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
  167. </span><span class="pun">}</span><span class="pln">
  168. fadeRate </span><span class="pun">=</span><span class="pln"> brightnessVal</span><span class="pun">[</span><span class="pln">i</span><span class="pun">];</span><span class="pln">
  169. fadeRate </span><span class="pun">=</span><span class="pln"> constrain</span><span class="pun">(</span><span class="pln">fadeRate</span><span class="pun">,</span><span class="lit">0</span><span class="pun">,</span><span class="lit">255</span><span class="pun">);</span><span class="pln"> </span><span class="com">// Keep LED fade value from going into negative numbers</span><span class="pln">
  170. setStrip</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="lit">0</span><span class="pun">,</span><span class="pln">fadeRate</span><span class="pun">,</span><span class="pln"> BPM</span><span class="pun">);</span><span class="pln">
  171. </span><span class="pun">}</span><span class="pln">
  172. </span><span class="kwd">else</span><span class="pln"> </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">BPM </span><span class="pun">>=</span><span class="pln"> </span><span class="lit">100</span><span class="pln"> </span><span class="kwd">and</span><span class="pln"> BPM </span><span class="pun"><</span><span class="pln"> </span><span class="lit">120</span><span class="pun">){</span><span class="pln">
  173. i</span><span class="pun">+=</span><span class="lit">4</span><span class="pun">;</span><span class="pln">
  174. </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">i </span><span class="pun">>=</span><span class="pln"> </span><span class="lit">201</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  175. i </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
  176. </span><span class="pun">}</span><span class="pln">
  177. fadeRate </span><span class="pun">=</span><span class="pln"> brightnessVal</span><span class="pun">[</span><span class="pln">i</span><span class="pun">];</span><span class="pln">
  178. fadeRate </span><span class="pun">=</span><span class="pln"> constrain</span><span class="pun">(</span><span class="pln">fadeRate</span><span class="pun">,</span><span class="lit">0</span><span class="pun">,</span><span class="lit">255</span><span class="pun">);</span><span class="pln"> </span><span class="com">// Keep LED fade value from going into negative numbers</span><span class="pln">
  179. setStrip</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="lit">0</span><span class="pun">,</span><span class="pln">fadeRate</span><span class="pun">,</span><span class="pln"> BPM</span><span class="pun">);</span><span class="pln">
  180. </span><span class="pun">}</span><span class="pln">
  181. </span><span class="kwd">else</span><span class="pln"> </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">BPM </span><span class="pun">>=</span><span class="pln"> </span><span class="lit">120</span><span class="pln"> </span><span class="kwd">and</span><span class="pln"> BPM </span><span class="pun"><</span><span class="pln"> </span><span class="lit">150</span><span class="pun">){</span><span class="pln">
  182. i</span><span class="pun">+=</span><span class="lit">5</span><span class="pun">;</span><span class="pln">
  183. </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">i </span><span class="pun">>=</span><span class="pln"> </span><span class="lit">201</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  184. i </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
  185. </span><span class="pun">}</span><span class="pln">
  186. fadeRate </span><span class="pun">=</span><span class="pln"> brightnessVal</span><span class="pun">[</span><span class="pln">i</span><span class="pun">];</span><span class="pln">
  187. fadeRate </span><span class="pun">=</span><span class="pln"> constrain</span><span class="pun">(</span><span class="pln">fadeRate</span><span class="pun">,</span><span class="lit">0</span><span class="pun">,</span><span class="lit">255</span><span class="pun">);</span><span class="pln"> </span><span class="com">// Keep LED fade value from going into negative numbers</span><span class="pln">
  188. setStrip</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="lit">0</span><span class="pun">,</span><span class="pln">fadeRate</span><span class="pun">,</span><span class="pln"> BPM</span><span class="pun">);</span><span class="pln">
  189. </span><span class="pun">}</span><span class="pln">
  190. </span><span class="kwd">else</span><span class="pun">{</span><span class="pln">
  191. </span><span class="kwd">for</span><span class="pln"> </span><span class="pun">(</span><span class="kwd">int</span><span class="pln"> x</span><span class="pun">=</span><span class="lit">0</span><span class="pun">;</span><span class="pln"> x </span><span class="pun"><</span><span class="pln"> NUMPIXELS</span><span class="pun">;</span><span class="pln"> x</span><span class="pun">++)</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="com">// Initialize all pixels to 'off'</span><span class="pln">
  192. strip</span><span class="pun">.</span><span class="pln">setPixelColor</span><span class="pun">(</span><span class="pln">x</span><span class="pun">,</span><span class="pln"> strip</span><span class="pun">.</span><span class="typ">Color</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">));</span><span class="pln">
  193. </span><span class="pun">}</span><span class="pln">
  194. strip</span><span class="pun">.</span><span class="pln">show</span><span class="pun">();</span><span class="pln">
  195. i</span><span class="pun">=</span><span class="lit">0</span><span class="pun">;</span><span class="pln">
  196. </span><span class="pun">}</span><span class="pln">
  197. </span><span class="com">// Serial.print("i=");</span><span class="pln">
  198. </span><span class="com">// Serial.println(i);</span><span class="pln">
  199. </span><span class="com">// sendDataSerial('R',fadeRate);</span><span class="pln">
  200. </span><span class="pun">}</span><span class="pln">
  201. </span><span class="kwd">void</span><span class="pln"> sendDataSerial</span><span class="pun">(</span><span class="kwd">char</span><span class="pln"> symbol</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> data </span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  202. </span><span class="com">// Serial.print(symbol); // symbol prefix tells Processing what type of data is coming</span><span class="pln">
  203. </span><span class="com">// Serial.println(data); // the data to send culminating in a carriage return</span><span class="pln">
  204. </span><span class="pun">}</span><span class="pln">
  205. </span><span class="kwd">void</span><span class="pln"> setStrip</span><span class="pun">(</span><span class="kwd">int</span><span class="pln"> r</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> g</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> b</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> BPM</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="com">// Set the strip to one color intensity (blue)</span><span class="pln">
  206. </span><span class="kwd">for</span><span class="pln"> </span><span class="pun">(</span><span class="kwd">int</span><span class="pln"> x</span><span class="pun">=</span><span class="lit">0</span><span class="pun">;</span><span class="pln"> x </span><span class="pun"><</span><span class="pln"> NUMPIXELS</span><span class="pun">;</span><span class="pln"> x</span><span class="pun">++)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  207. strip</span><span class="pun">.</span><span class="pln">setPixelColor</span><span class="pun">(</span><span class="pln">x</span><span class="pun">,</span><span class="pln"> strip</span><span class="pun">.</span><span class="typ">Color</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> b</span><span class="pun">));</span><span class="pln">
  208. </span><span class="pun">}</span><span class="pln">
  209. strip</span><span class="pun">.</span><span class="pln">show</span><span class="pun">();</span><span class="pln">
  210. </span><span class="pun">}</span><span class="pln">
  211. </span><span class="com">/*
  212. sending the 10 most recent bpm values to receiver
  213. */</span><span class="pln">
  214. </span><span class="kwd">void</span><span class="pln"> send</span><span class="pun">(</span><span class="kwd">int</span><span class="pln"> bpmAvg</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="com">// function for radio </span><span class="pln">
  215. </span><span class="com">// shift every BPM value to the right for the new bpmAvg</span><span class="pln">
  216. </span><span class="kwd">for</span><span class="pln"> </span><span class="pun">(</span><span class="kwd">int</span><span class="pln"> i</span><span class="pun">=</span><span class="lit">0</span><span class="pun">;</span><span class="pln"> i</span><span class="pun"><</span><span class="lit">9</span><span class="pun">;</span><span class="pln"> i</span><span class="pun">++){</span><span class="pln">
  217. dailyBPM</span><span class="pun">[</span><span class="pln">i</span><span class="pun">+</span><span class="lit">1</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> dailyBPM</span><span class="pun">[</span><span class="pln">i</span><span class="pun">];</span><span class="pln">
  218. </span><span class="pun">}</span><span class="pln">
  219. dailyBPM</span><span class="pun">[</span><span class="lit">0</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> bpmAvg</span><span class="pun">;</span><span class="pln"> </span><span class="com">//putting newest bpmAvg value at the front of array</span><span class="pln">
  220. </span><span class="kwd">bool</span><span class="pln"> rslt </span><span class="pun">=</span><span class="pln"> radio</span><span class="pun">.</span><span class="pln">write</span><span class="pun">(</span><span class="pln"> </span><span class="pun">&</span><span class="pln">dailyBPM</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">sizeof</span><span class="pun">(</span><span class="pln">dailyBPM</span><span class="pun">)</span><span class="pln"> </span><span class="pun">);</span><span class="pln">
  221. </span><span class="com">// Always use sizeof() as it gives the size as the number of bytes.</span><span class="pln">
  222. </span><span class="com">// For example if dataToSend was an int sizeof() would correctly return 2</span><span class="pln">
  223. </span><span class="typ">Serial</span><span class="pun">.</span><span class="kwd">print</span><span class="pun">(</span><span class="str">"Data Sent "</span><span class="pun">);</span><span class="pln">
  224. </span><span class="kwd">for</span><span class="pln"> </span><span class="pun">(</span><span class="kwd">int</span><span class="pln"> x </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln"> x </span><span class="pun"><</span><span class="pln"> </span><span class="pun">(</span><span class="kwd">sizeof</span><span class="pun">(</span><span class="pln">dailyBPM</span><span class="pun">)</span><span class="pln"> </span><span class="pun">/</span><span class="pln"> </span><span class="kwd">sizeof</span><span class="pun">(</span><span class="pln">dailyBPM</span><span class="pun">[</span><span class="lit">0</span><span class="pun">]));</span><span class="pln"> x</span><span class="pun">++)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  225. </span><span class="typ">Serial</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="pln">dailyBPM</span><span class="pun">[</span><span class="pln">x</span><span class="pun">]);</span><span class="pln">
  226. </span><span class="pun">}</span><span class="pln">
  227. </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">rslt</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  228. </span><span class="typ">Serial</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">" Acknowledge received"</span><span class="pun">);</span><span class="pln">
  229. memset</span><span class="pun">(</span><span class="pln">dailyBPM</span><span class="pun">,</span><span class="pln"> </span><span class="pun">-</span><span class="lit">1</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">sizeof</span><span class="pun">(</span><span class="pln">dailyBPM</span><span class="pun">));</span><span class="pln">
  230. </span><span class="com">// for (int x = 0; x < sizeof(dailyBPM) / sizeof(dailyBPM[0]); x++)</span><span class="pln">
  231. </span><span class="com">// updateMessage();</span><span class="pln">
  232. </span><span class="pun">}</span><span class="pln">
  233. </span><span class="kwd">else</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  234. </span><span class="typ">Serial</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">" Tx failed"</span><span class="pun">);</span><span class="pln">
  235. </span><span class="pun">}</span><span class="pln">
  236. </span><span class="pun">}</span>
<span class="com">/* 
 *  Mindfulness Device
 *  
 *  Karen Kim + Ian Shei 
 *  
 *  This code uses a pulse sensor to measure heart rate
 *  and display it through an LED ring. There are 
 *  different thresholds that determine the speed
 *  of the pulsing of the LED ring. 
 *  
 *  Input: heart rate sensor (A0), capacitative sensor (Pin 6) 
 *  Output: LED ring (Pin 5) 
 *  
 *  Example code used from: 
   http://pulsesensor.com/pages/pulse-sensor-amped-arduino-v1dot1
   Version 1.0 by Mike Barela for Adafruit Industries, Fall 2015
*/</span><span class="pln">

</span><span class="com">#include</span><span class="pln"> </span><span class="str"><Adafruit_NeoPixel.h></span><span class="pln">    </span><span class="com">// Library containing</span><span class="pln">
</span><span class="com">#include</span><span class="pln"> </span><span class="str"><SPI.h></span><span class="pln">
</span><span class="com">#include</span><span class="pln"> </span><span class="str"><nRF24L01.h></span><span class="pln">
</span><span class="com">#include</span><span class="pln"> </span><span class="str"><RF24.h></span><span class="pln">

</span><span class="com">#define</span><span class="pln"> CE_PIN   </span><span class="lit">9</span><span class="pln">
</span><span class="com">#define</span><span class="pln"> CSN_PIN </span><span class="lit">10</span><span class="pln">

</span><span class="com">// Behavior setting variables</span><span class="pln">
</span><span class="kwd">int</span><span class="pln"> pulsePin </span><span class="pun">=</span><span class="pln"> A0</span><span class="pun">;</span><span class="pln">                 </span><span class="com">// Pulse Sensor purple wire connected to analog pin 0</span><span class="pln">
</span><span class="kwd">int</span><span class="pln"> blinkPin </span><span class="pun">=</span><span class="pln"> </span><span class="lit">13</span><span class="pun">;</span><span class="pln">                </span><span class="com">// Digital pin to blink led at each beat</span><span class="pln">
</span><span class="kwd">int</span><span class="pln"> ringPin  </span><span class="pun">=</span><span class="pln"> </span><span class="lit">5</span><span class="pun">;</span><span class="pln">                 </span><span class="com">// pin to do fancy neopixel effects at each beat</span><span class="pln">
</span><span class="kwd">int</span><span class="pln"> fadeRate </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">                 </span><span class="com">// used to fade LED on with PWM on ringPin</span><span class="pln">
</span><span class="kwd">int</span><span class="pln"> sensorPin </span><span class="pun">=</span><span class="pln"> </span><span class="lit">6</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> motorPin </span><span class="pun">=</span><span class="pln"> </span><span class="lit">3</span><span class="pun">;</span><span class="pln">

</span><span class="com">// array for LED brightness pulsing values </span><span class="pln">
</span><span class="kwd">int</span><span class="pln"> brightnessVal </span><span class="pun">[</span><span class="lit">201</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="pun">{</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">1</span><span class="pun">,</span><span class="pln"> </span><span class="lit">1</span><span class="pun">,</span><span class="pln"> </span><span class="lit">2</span><span class="pun">,</span><span class="pln"> </span><span class="lit">2</span><span class="pun">,</span><span class="pln"> </span><span class="lit">3</span><span class="pun">,</span><span class="pln"> </span><span class="lit">4</span><span class="pun">,</span><span class="pln"> </span><span class="lit">5</span><span class="pun">,</span><span class="pln"> </span><span class="lit">6</span><span class="pun">,</span><span class="pln"> </span><span class="lit">8</span><span class="pun">,</span><span class="pln"> </span><span class="lit">9</span><span class="pun">,</span><span class="pln"> </span><span class="lit">10</span><span class="pun">,</span><span class="pln"> </span><span class="lit">12</span><span class="pun">,</span><span class="pln"> </span><span class="lit">14</span><span class="pun">,</span><span class="pln"> </span><span class="lit">16</span><span class="pun">,</span><span class="pln"> </span><span class="lit">18</span><span class="pun">,</span><span class="pln"> </span><span class="lit">20</span><span class="pun">,</span><span class="pln"> </span><span class="lit">22</span><span class="pun">,</span><span class="pln"> </span><span class="lit">24</span><span class="pun">,</span><span class="pln"> </span><span class="lit">27</span><span class="pun">,</span><span class="pln"> </span><span class="lit">29</span><span class="pun">,</span><span class="pln"> </span><span class="lit">32</span><span class="pun">,</span><span class="pln"> </span><span class="lit">35</span><span class="pun">,</span><span class="pln"> </span><span class="lit">37</span><span class="pun">,</span><span class="pln"> </span><span class="lit">40</span><span class="pun">,</span><span class="pln"> </span><span class="lit">43</span><span class="pun">,</span><span class="pln"> </span><span class="lit">46</span><span class="pun">,</span><span class="pln"> </span><span class="lit">49</span><span class="pun">,</span><span class="pln"> </span><span class="lit">53</span><span class="pun">,</span><span class="pln"> </span><span class="lit">56</span><span class="pun">,</span><span class="pln"> </span><span class="lit">59</span><span class="pun">,</span><span class="pln"> </span><span class="lit">63</span><span class="pun">,</span><span class="pln"> </span><span class="lit">66</span><span class="pun">,</span><span class="pln"> </span><span class="lit">70</span><span class="pun">,</span><span class="pln"> </span><span class="lit">73</span><span class="pun">,</span><span class="pln"> </span><span class="lit">77</span><span class="pun">,</span><span class="pln"> </span><span class="lit">81</span><span class="pun">,</span><span class="pln"> </span><span class="lit">84</span><span class="pun">,</span><span class="pln"> </span><span class="lit">88</span><span class="pun">,</span><span class="pln"> </span><span class="lit">92</span><span class="pun">,</span><span class="pln"> </span><span class="lit">96</span><span class="pun">,</span><span class="pln"> </span><span class="lit">100</span><span class="pun">,</span><span class="pln"> </span><span class="lit">104</span><span class="pun">,</span><span class="pln"> </span><span class="lit">108</span><span class="pun">,</span><span class="pln"> </span><span class="lit">112</span><span class="pun">,</span><span class="pln"> </span><span class="lit">116</span><span class="pun">,</span><span class="pln"> </span><span class="lit">119</span><span class="pun">,</span><span class="pln"> </span><span class="lit">123</span><span class="pun">,</span><span class="pln"> </span><span class="lit">128</span><span class="pun">,</span><span class="pln"> </span><span class="lit">132</span><span class="pun">,</span><span class="pln"> </span><span class="lit">136</span><span class="pun">,</span><span class="pln"> </span><span class="lit">139</span><span class="pun">,</span><span class="pln"> </span><span class="lit">143</span><span class="pun">,</span><span class="pln"> </span><span class="lit">147</span><span class="pun">,</span><span class="pln"> </span><span class="lit">151</span><span class="pun">,</span><span class="pln"> </span><span class="lit">155</span><span class="pun">,</span><span class="pln"> </span><span class="lit">159</span><span class="pun">,</span><span class="pln"> </span><span class="lit">163</span><span class="pun">,</span><span class="pln"> </span><span class="lit">167</span><span class="pun">,</span><span class="pln"> </span><span class="lit">171</span><span class="pun">,</span><span class="pln"> </span><span class="lit">174</span><span class="pun">,</span><span class="pln"> </span><span class="lit">178</span><span class="pun">,</span><span class="pln"> </span><span class="lit">182</span><span class="pun">,</span><span class="pln"> </span><span class="lit">185</span><span class="pun">,</span><span class="pln"> </span><span class="lit">189</span><span class="pun">,</span><span class="pln"> </span><span class="lit">192</span><span class="pun">,</span><span class="pln"> </span><span class="lit">196</span><span class="pun">,</span><span class="pln"> </span><span class="lit">199</span><span class="pun">,</span><span class="pln"> </span><span class="lit">202</span><span class="pun">,</span><span class="pln"> </span><span class="lit">206</span><span class="pun">,</span><span class="pln"> </span><span class="lit">209</span><span class="pun">,</span><span class="pln"> </span><span class="lit">212</span><span class="pun">,</span><span class="pln"> </span><span class="lit">215</span><span class="pun">,</span><span class="pln"> </span><span class="lit">218</span><span class="pun">,</span><span class="pln"> </span><span class="lit">220</span><span class="pun">,</span><span class="pln"> </span><span class="lit">223</span><span class="pun">,</span><span class="pln"> </span><span class="lit">226</span><span class="pun">,</span><span class="pln"> </span><span class="lit">228</span><span class="pun">,</span><span class="pln"> </span><span class="lit">231</span><span class="pun">,</span><span class="pln"> </span><span class="lit">233</span><span class="pun">,</span><span class="pln"> </span><span class="lit">235</span><span class="pun">,</span><span class="pln"> </span><span class="lit">237</span><span class="pun">,</span><span class="pln"> </span><span class="lit">239</span><span class="pun">,</span><span class="pln"> </span><span class="lit">241</span><span class="pun">,</span><span class="pln"> </span><span class="lit">243</span><span class="pun">,</span><span class="pln"> </span><span class="lit">245</span><span class="pun">,</span><span class="pln"> </span><span class="lit">246</span><span class="pun">,</span><span class="pln"> </span><span class="lit">247</span><span class="pun">,</span><span class="pln"> </span><span class="lit">249</span><span class="pun">,</span><span class="pln"> </span><span class="lit">250</span><span class="pun">,</span><span class="pln"> </span><span class="lit">251</span><span class="pun">,</span><span class="pln"> </span><span class="lit">252</span><span class="pun">,</span><span class="pln"> </span><span class="lit">253</span><span class="pun">,</span><span class="pln"> </span><span class="lit">253</span><span class="pun">,</span><span class="pln"> </span><span class="lit">254</span><span class="pun">,</span><span class="pln"> </span><span class="lit">254</span><span class="pun">,</span><span class="pln"> </span><span class="lit">255</span><span class="pun">,</span><span class="pln"> </span><span class="lit">255</span><span class="pun">,</span><span class="pln"> </span><span class="lit">255</span><span class="pun">,</span><span class="pln"> </span><span class="lit">255</span><span class="pun">,</span><span class="pln"> </span><span class="lit">255</span><span class="pun">,</span><span class="pln"> </span><span class="lit">254</span><span class="pun">,</span><span class="pln"> </span><span class="lit">254</span><span class="pun">,</span><span class="pln"> </span><span class="lit">253</span><span class="pun">,</span><span class="pln"> </span><span class="lit">253</span><span class="pun">,</span><span class="pln"> </span><span class="lit">252</span><span class="pun">,</span><span class="pln"> </span><span class="lit">251</span><span class="pun">,</span><span class="pln"> </span><span class="lit">250</span><span class="pun">,</span><span class="pln"> </span><span class="lit">249</span><span class="pun">,</span><span class="pln"> </span><span class="lit">247</span><span class="pun">,</span><span class="pln"> </span><span class="lit">246</span><span class="pun">,</span><span class="pln"> </span><span class="lit">245</span><span class="pun">,</span><span class="pln"> </span><span class="lit">243</span><span class="pun">,</span><span class="pln"> </span><span class="lit">241</span><span class="pun">,</span><span class="pln"> </span><span class="lit">239</span><span class="pun">,</span><span class="pln"> </span><span class="lit">237</span><span class="pun">,</span><span class="pln"> </span><span class="lit">235</span><span class="pun">,</span><span class="pln"> </span><span class="lit">233</span><span class="pun">,</span><span class="pln"> </span><span class="lit">231</span><span class="pun">,</span><span class="pln"> </span><span class="lit">228</span><span class="pun">,</span><span class="pln"> </span><span class="lit">226</span><span class="pun">,</span><span class="pln"> </span><span class="lit">223</span><span class="pun">,</span><span class="pln"> </span><span class="lit">220</span><span class="pun">,</span><span class="pln"> </span><span class="lit">218</span><span class="pun">,</span><span class="pln"> </span><span class="lit">215</span><span class="pun">,</span><span class="pln"> </span><span class="lit">212</span><span class="pun">,</span><span class="pln"> </span><span class="lit">209</span><span class="pun">,</span><span class="pln"> </span><span class="lit">206</span><span class="pun">,</span><span class="pln"> </span><span class="lit">202</span><span class="pun">,</span><span class="pln"> </span><span class="lit">199</span><span class="pun">,</span><span class="pln"> </span><span class="lit">196</span><span class="pun">,</span><span class="pln"> </span><span class="lit">192</span><span class="pun">,</span><span class="pln"> </span><span class="lit">189</span><span class="pun">,</span><span class="pln"> </span><span class="lit">185</span><span class="pun">,</span><span class="pln"> </span><span class="lit">182</span><span class="pun">,</span><span class="pln"> </span><span class="lit">178</span><span class="pun">,</span><span class="pln"> </span><span class="lit">174</span><span class="pun">,</span><span class="pln"> </span><span class="lit">171</span><span class="pun">,</span><span class="pln"> </span><span class="lit">167</span><span class="pun">,</span><span class="pln"> </span><span class="lit">163</span><span class="pun">,</span><span class="pln"> </span><span class="lit">159</span><span class="pun">,</span><span class="pln"> </span><span class="lit">155</span><span class="pun">,</span><span class="pln"> </span><span class="lit">151</span><span class="pun">,</span><span class="pln"> </span><span class="lit">147</span><span class="pun">,</span><span class="pln"> </span><span class="lit">143</span><span class="pun">,</span><span class="pln"> </span><span class="lit">139</span><span class="pun">,</span><span class="pln"> </span><span class="lit">136</span><span class="pun">,</span><span class="pln"> </span><span class="lit">132</span><span class="pun">,</span><span class="pln"> </span><span class="lit">128</span><span class="pun">,</span><span class="pln"> </span><span class="lit">123</span><span class="pun">,</span><span class="pln"> </span><span class="lit">119</span><span class="pun">,</span><span class="pln"> </span><span class="lit">116</span><span class="pun">,</span><span class="pln"> </span><span class="lit">112</span><span class="pun">,</span><span class="pln"> </span><span class="lit">108</span><span class="pun">,</span><span class="pln"> </span><span class="lit">104</span><span class="pun">,</span><span class="pln"> </span><span class="lit">100</span><span class="pun">,</span><span class="pln"> </span><span class="lit">96</span><span class="pun">,</span><span class="pln"> </span><span class="lit">92</span><span class="pun">,</span><span class="pln"> </span><span class="lit">88</span><span class="pun">,</span><span class="pln"> </span><span class="lit">84</span><span class="pun">,</span><span class="pln"> </span><span class="lit">81</span><span class="pun">,</span><span class="pln"> </span><span class="lit">77</span><span class="pun">,</span><span class="pln"> </span><span class="lit">73</span><span class="pun">,</span><span class="pln"> </span><span class="lit">70</span><span class="pun">,</span><span class="pln"> </span><span class="lit">66</span><span class="pun">,</span><span class="pln"> </span><span class="lit">63</span><span class="pun">,</span><span class="pln"> </span><span class="lit">59</span><span class="pun">,</span><span class="pln"> </span><span class="lit">56</span><span class="pun">,</span><span class="pln"> </span><span class="lit">53</span><span class="pun">,</span><span class="pln"> </span><span class="lit">49</span><span class="pun">,</span><span class="pln"> </span><span class="lit">46</span><span class="pun">,</span><span class="pln"> </span><span class="lit">43</span><span class="pun">,</span><span class="pln"> </span><span class="lit">40</span><span class="pun">,</span><span class="pln"> </span><span class="lit">37</span><span class="pun">,</span><span class="pln"> </span><span class="lit">35</span><span class="pun">,</span><span class="pln"> </span><span class="lit">32</span><span class="pun">,</span><span class="pln"> </span><span class="lit">29</span><span class="pun">,</span><span class="pln"> </span><span class="lit">27</span><span class="pun">,</span><span class="pln"> </span><span class="lit">24</span><span class="pun">,</span><span class="pln"> </span><span class="lit">22</span><span class="pun">,</span><span class="pln"> </span><span class="lit">20</span><span class="pun">,</span><span class="pln"> </span><span class="lit">18</span><span class="pun">,</span><span class="pln"> </span><span class="lit">16</span><span class="pun">,</span><span class="pln"> </span><span class="lit">14</span><span class="pun">,</span><span class="pln"> </span><span class="lit">12</span><span class="pun">,</span><span class="pln"> </span><span class="lit">10</span><span class="pun">,</span><span class="pln"> </span><span class="lit">9</span><span class="pun">,</span><span class="pln"> </span><span class="lit">8</span><span class="pun">,</span><span class="pln"> </span><span class="lit">6</span><span class="pun">,</span><span class="pln"> </span><span class="lit">5</span><span class="pun">,</span><span class="pln"> </span><span class="lit">4</span><span class="pun">,</span><span class="pln"> </span><span class="lit">3</span><span class="pun">,</span><span class="pln"> </span><span class="lit">2</span><span class="pun">,</span><span class="pln"> </span><span class="lit">2</span><span class="pun">,</span><span class="pln"> </span><span class="lit">1</span><span class="pun">,</span><span class="pln"> </span><span class="lit">1</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">};</span><span class="pln">

</span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">byte</span><span class="pln"> slaveAddress</span><span class="pun">[</span><span class="lit">5</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="pun">{</span><span class="str">'R'</span><span class="pun">,</span><span class="str">'x'</span><span class="pun">,</span><span class="str">'A'</span><span class="pun">,</span><span class="str">'A'</span><span class="pun">,</span><span class="str">'A'</span><span class="pun">};</span><span class="pln"> </span><span class="com">// for radio </span><span class="pln">
RF24 radio</span><span class="pun">(</span><span class="pln">CE_PIN</span><span class="pun">,</span><span class="pln"> CSN_PIN</span><span class="pun">);</span><span class="pln"> </span><span class="com">// Create a Radio</span><span class="pln">

</span><span class="kwd">char</span><span class="pln"> message</span><span class="pun">[</span><span class="lit">10</span><span class="pun">];</span><span class="pln"> </span><span class="com">// array length for radio message </span><span class="pln">
</span><span class="kwd">char</span><span class="pln"> txNum </span><span class="pun">=</span><span class="pln"> </span><span class="str">'0'</span><span class="pun">;</span><span class="pln">

</span><span class="kwd">unsigned</span><span class="pln"> </span><span class="kwd">long</span><span class="pln"> currentMillis</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">unsigned</span><span class="pln"> </span><span class="kwd">long</span><span class="pln"> prevMillis</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">unsigned</span><span class="pln"> </span><span class="kwd">long</span><span class="pln"> txIntervalMillis </span><span class="pun">=</span><span class="pln"> </span><span class="lit">1000</span><span class="pun">;</span><span class="pln"> </span><span class="com">// send once per second</span><span class="pln">


</span><span class="com">// these variables are volatile because they are used during the interrupt service routine</span><span class="pln">
</span><span class="kwd">volatile</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> BPM</span><span class="pun">;</span><span class="pln">                   </span><span class="com">// used to hold the pulse rate</span><span class="pln">
</span><span class="kwd">volatile</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> </span><span class="typ">Signal</span><span class="pun">;</span><span class="pln">                </span><span class="com">// holds the incoming raw data</span><span class="pln">
</span><span class="kwd">volatile</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> IBI </span><span class="pun">=</span><span class="pln"> </span><span class="lit">600</span><span class="pun">;</span><span class="pln">             </span><span class="com">// holds the time between beats, the Inter-Beat Interval</span><span class="pln">
</span><span class="kwd">volatile</span><span class="pln"> </span><span class="kwd">boolean</span><span class="pln"> </span><span class="typ">Pulse</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">;</span><span class="pln">     </span><span class="com">// true when pulse wave is high, false when it's low</span><span class="pln">
</span><span class="kwd">volatile</span><span class="pln"> </span><span class="kwd">boolean</span><span class="pln"> QS </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">;</span><span class="pln">        </span><span class="com">// becomes true when Arduoino finds a beat.</span><span class="pln">

</span><span class="com">// Set up use of NeoPixels</span><span class="pln">
</span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> NUMPIXELS </span><span class="pun">=</span><span class="pln"> </span><span class="lit">24</span><span class="pun">;</span><span class="pln">           </span><span class="com">// Put the number of NeoPixels you are using here</span><span class="pln">
</span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> BRIGHTNESS </span><span class="pun">=</span><span class="pln"> </span><span class="lit">60</span><span class="pun">;</span><span class="pln">          </span><span class="com">// Set brightness of NeoPixels here</span><span class="pln">
</span><span class="typ">Adafruit_NeoPixel</span><span class="pln"> strip </span><span class="pun">=</span><span class="pln"> </span><span class="typ">Adafruit_NeoPixel</span><span class="pun">(</span><span class="lit">24</span><span class="pun">,</span><span class="pln"> ringPin</span><span class="pun">,</span><span class="pln"> NEO_GRBW </span><span class="pun">+</span><span class="pln"> NEO_KHZ800</span><span class="pun">);</span><span class="pln">

</span><span class="kwd">unsigned</span><span class="pln"> </span><span class="kwd">long</span><span class="pln"> startMillis</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">bool</span><span class="pln"> inTrial </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">bool</span><span class="pln"> inWait </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">bool</span><span class="pln"> turnOn </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">;</span><span class="pln">

</span><span class="kwd">int</span><span class="pln"> bpmCount </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">int</span><span class="pln"> bpmAvg </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">int</span><span class="pln"> totalBPM </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">int</span><span class="pln"> dailyBPM</span><span class="pun">[</span><span class="lit">10</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="pun">{-</span><span class="lit">1</span><span class="pun">,-</span><span class="lit">1</span><span class="pun">,-</span><span class="lit">1</span><span class="pun">,-</span><span class="lit">1</span><span class="pun">,-</span><span class="lit">1</span><span class="pun">,-</span><span class="lit">1</span><span class="pun">,-</span><span class="lit">1</span><span class="pun">,-</span><span class="lit">1</span><span class="pun">,-</span><span class="lit">1</span><span class="pun">,-</span><span class="lit">1</span><span class="pun">};</span><span class="pln">

</span><span class="kwd">void</span><span class="pln"> setup</span><span class="pun">(){</span><span class="pln">
  pinMode</span><span class="pun">(</span><span class="pln">blinkPin</span><span class="pun">,</span><span class="pln">OUTPUT</span><span class="pun">);</span><span class="pln">         </span><span class="com">// pin that will blink to your heartbeat!</span><span class="pln">
  pinMode</span><span class="pun">(</span><span class="pln">motorPin</span><span class="pun">,</span><span class="pln"> OUTPUT</span><span class="pun">);</span><span class="pln">
  pinMode</span><span class="pun">(</span><span class="pln">sensorPin</span><span class="pun">,</span><span class="pln"> INPUT</span><span class="pun">);</span><span class="pln">
  </span><span class="typ">Serial</span><span class="pun">.</span><span class="kwd">begin</span><span class="pun">(</span><span class="lit">9600</span><span class="pun">);</span><span class="pln">           </span><span class="com">// Serial output data for debugging or external use</span><span class="pln">
  strip</span><span class="pun">.</span><span class="kwd">begin</span><span class="pun">();</span><span class="pln">
  strip</span><span class="pun">.</span><span class="pln">setBrightness</span><span class="pun">(</span><span class="pln">BRIGHTNESS</span><span class="pun">);</span><span class="pln">
  </span><span class="kwd">for</span><span class="pln"> </span><span class="pun">(</span><span class="kwd">int</span><span class="pln"> x</span><span class="pun">=</span><span class="lit">0</span><span class="pun">;</span><span class="pln"> x </span><span class="pun"><</span><span class="pln"> NUMPIXELS</span><span class="pun">;</span><span class="pln"> x</span><span class="pun">++)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">  </span><span class="com">// Initialize all pixels to 'off'</span><span class="pln">
     strip</span><span class="pun">.</span><span class="pln">setPixelColor</span><span class="pun">(</span><span class="pln">x</span><span class="pun">,</span><span class="pln"> strip</span><span class="pun">.</span><span class="typ">Color</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">));</span><span class="pln">
  </span><span class="pun">}</span><span class="pln">
  strip</span><span class="pun">.</span><span class="pln">show</span><span class="pun">();</span><span class="pln">                     </span><span class="com">// Ensure the pixels are off</span><span class="pln">
  delay</span><span class="pun">(</span><span class="lit">1000</span><span class="pun">);</span><span class="pln">                      </span><span class="com">// Wait a second</span><span class="pln">
  interruptSetup</span><span class="pun">();</span><span class="pln">                 </span><span class="com">// sets up to read Pulse Sensor signal every 2mS</span><span class="pln">

   radio</span><span class="pun">.</span><span class="kwd">begin</span><span class="pun">();</span><span class="pln">
   radio</span><span class="pun">.</span><span class="pln">setDataRate</span><span class="pun">(</span><span class="pln"> RF24_250KBPS </span><span class="pun">);</span><span class="pln">
   radio</span><span class="pun">.</span><span class="pln">setRetries</span><span class="pun">(</span><span class="lit">3</span><span class="pun">,</span><span class="lit">5</span><span class="pun">);</span><span class="pln"> </span><span class="com">// delay, count</span><span class="pln">
   radio</span><span class="pun">.</span><span class="pln">openWritingPipe</span><span class="pun">(</span><span class="pln">slaveAddress</span><span class="pun">);</span><span class="pln">
</span><span class="pun">}</span><span class="pln">

</span><span class="kwd">void</span><span class="pln"> loop</span><span class="pun">(){</span><span class="pln">
  </span><span class="kwd">int</span><span class="pln"> sensorRead </span><span class="pun">=</span><span class="pln"> digitalRead</span><span class="pun">(</span><span class="pln">sensorPin</span><span class="pun">);</span><span class="pln">
  </span><span class="com">// Serial.println(sensorRead);</span><span class="pln">

  </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">sensorRead </span><span class="pun">==</span><span class="pln"> HIGH</span><span class="pun">){</span><span class="pln"> </span><span class="com">// use capaacitative sensor to turn on device </span><span class="pln">
    turnOn </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">;</span><span class="pln">
  </span><span class="pun">}</span><span class="pln">

  </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">turnOn </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">){</span><span class="pln">
  </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">inWait </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">false</span><span class="pln"> </span><span class="kwd">and</span><span class="pln"> inTrial </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">false</span><span class="pln"> </span><span class="kwd">and</span><span class="pln"> QS </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">){</span><span class="pln">  </span><span class="com">// Quantified Self flag is true when arduino finds a heartbeat</span><span class="pln">
</span><span class="com">//    analogWrite(motorPin, 100);</span><span class="pln">
     </span><span class="typ">Serial</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"START WAIT"</span><span class="pun">);</span><span class="pln"> </span><span class="com">// setting 5 second baseline for heartrate </span><span class="pln">
     inWait </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">;</span><span class="pln">
</span><span class="com">//     inTrial = true;</span><span class="pln">
     startMillis </span><span class="pun">=</span><span class="pln"> millis</span><span class="pun">();</span><span class="pln">
</span><span class="com">//     fadeRate = 255;                  // Set 'fadeRate' Variable to 255 to fade LED with pulse</span><span class="pln">
     </span><span class="typ">Serial</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="pln">BPM</span><span class="pun">);</span><span class="pln">
</span><span class="com">//     sendDataSerial('B',BPM);       // send heart rate with a 'B' prefix</span><span class="pln">
</span><span class="com">//     sendDataSerial('Q',IBI);       // send time between beats with a 'Q' prefix</span><span class="pln">
     QS </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">;</span><span class="pln">                      </span><span class="com">// reset the Quantified Self flag for next time</span><span class="pln">
  </span><span class="pun">}</span><span class="pln">

  </span><span class="kwd">else</span><span class="pln"> </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">inWait </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">true</span><span class="pln"> </span><span class="kwd">and</span><span class="pln"> millis</span><span class="pun">()</span><span class="pln"> </span><span class="pun">-</span><span class="pln"> startMillis </span><span class="pun">>=</span><span class="pln"> </span><span class="lit">5000</span><span class="pun">){</span><span class="pln">
      </span><span class="typ">Serial</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"END WAIT"</span><span class="pun">);</span><span class="pln">

      inTrial </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">;</span><span class="pln">
      inWait </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">;</span><span class="pln">
      startMillis </span><span class="pun">=</span><span class="pln"> millis</span><span class="pun">();</span><span class="pln">
    </span><span class="pun">}</span><span class="pln">

  </span><span class="kwd">else</span><span class="pln"> </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">inTrial </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">true</span><span class="pln"> </span><span class="kwd">and</span><span class="pln"> QS </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">){</span><span class="pln">
    bpmAvg </span><span class="pun">=</span><span class="pln"> totalBPM</span><span class="pun">/</span><span class="pln">bpmCount</span><span class="pun">;</span><span class="pln">
</span><span class="com">//    Serial.println(bpmAvg);</span><span class="pln">
    </span><span class="typ">Serial</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"IN TRIAL"</span><span class="pun">);</span><span class="pln">
</span><span class="com">//    Serial.println(millis() - startMillis);</span><span class="pln">

    </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">millis</span><span class="pun">()</span><span class="pln"> </span><span class="pun">-</span><span class="pln"> startMillis </span><span class="pun">>=</span><span class="pln"> </span><span class="lit">5000</span><span class="pun">){</span><span class="pln">
      </span><span class="typ">Serial</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"END OF TRIAL"</span><span class="pun">);</span><span class="pln">
      inTrial </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">;</span><span class="pln">
      </span><span class="kwd">for</span><span class="pln"> </span><span class="pun">(</span><span class="kwd">int</span><span class="pln"> x</span><span class="pun">=</span><span class="lit">0</span><span class="pun">;</span><span class="pln"> x </span><span class="pun"><</span><span class="pln"> NUMPIXELS</span><span class="pun">;</span><span class="pln"> x</span><span class="pun">++)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">  </span><span class="com">// Initialize all pixels to 'off'</span><span class="pln">
        strip</span><span class="pun">.</span><span class="pln">setPixelColor</span><span class="pun">(</span><span class="pln">x</span><span class="pun">,</span><span class="pln"> strip</span><span class="pun">.</span><span class="typ">Color</span><span class="pun">(</span><span class="lit">255</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">));</span><span class="pln"> </span><span class="com">// blue light for during 1 minute cycle</span><span class="pln">
      </span><span class="pun">}</span><span class="pln">
      strip</span><span class="pun">.</span><span class="pln">show</span><span class="pun">();</span><span class="pln">
      send</span><span class="pun">(</span><span class="pln">bpmAvg</span><span class="pun">);</span><span class="pln">
      totalBPM</span><span class="pun">=</span><span class="lit">0</span><span class="pun">;</span><span class="pln">
      bpmCount</span><span class="pun">=</span><span class="lit">0</span><span class="pun">;</span><span class="pln">
      delay</span><span class="pun">(</span><span class="lit">1000</span><span class="pun">);</span><span class="pln">
      turnOn </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">;</span><span class="pln">
    </span><span class="pun">}</span><span class="pln">
 </span><span class="com">//   fadeRate = 400;</span><span class="pln">
    QS </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">;</span><span class="pln">
  </span><span class="pun">}</span><span class="pln">

  </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">inTrial </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">){</span><span class="pln">
    </span><span class="typ">Serial</span><span class="pun">.</span><span class="kwd">print</span><span class="pun">(</span><span class="str">"BPM="</span><span class="pun">);</span><span class="pln">
    </span><span class="typ">Serial</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="pln">BPM</span><span class="pun">);</span><span class="pln">
    totalBPM</span><span class="pun">+=</span><span class="pln">BPM</span><span class="pun">;</span><span class="pln">
    bpmCount</span><span class="pun">+=</span><span class="lit">1</span><span class="pun">;</span><span class="pln">
    ledFadeToBeat</span><span class="pun">(</span><span class="pln">BPM</span><span class="pun">);</span><span class="pln">                    </span><span class="com">// Routine that fades color intensity to the beat</span><span class="pln">
  </span><span class="pun">}</span><span class="pln">

  </span><span class="kwd">else</span><span class="pln"> </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">inWait </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
    </span><span class="kwd">for</span><span class="pln"> </span><span class="pun">(</span><span class="kwd">int</span><span class="pln"> x</span><span class="pun">=</span><span class="lit">0</span><span class="pun">;</span><span class="pln"> x </span><span class="pun"><</span><span class="pln"> NUMPIXELS</span><span class="pun">;</span><span class="pln"> x</span><span class="pun">++)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">  </span><span class="com">// Initialize all pixels to 'off'</span><span class="pln">
      strip</span><span class="pun">.</span><span class="pln">setPixelColor</span><span class="pun">(</span><span class="pln">x</span><span class="pun">,</span><span class="pln"> strip</span><span class="pun">.</span><span class="typ">Color</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">255</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">));</span><span class="pln"> </span><span class="com">// turns off after 1 minute</span><span class="pln">
      </span><span class="pun">}</span><span class="pln">
      strip</span><span class="pun">.</span><span class="pln">show</span><span class="pun">();</span><span class="pln">
  </span><span class="pun">}</span><span class="pln">

  </span><span class="kwd">else</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
    setStrip</span><span class="pun">(</span><span class="lit">255</span><span class="pun">,</span><span class="lit">0</span><span class="pun">,</span><span class="lit">0</span><span class="pun">,</span><span class="pln">BPM</span><span class="pun">);</span><span class="pln">
    delay</span><span class="pun">(</span><span class="lit">3000</span><span class="pun">);</span><span class="pln">
  </span><span class="pun">}</span><span class="pln">
  delay</span><span class="pun">(</span><span class="lit">100</span><span class="pun">);</span><span class="pln">                          </span><span class="com">//  take a break</span><span class="pln">
</span><span class="pun">}</span><span class="pln">
</span><span class="pun">}</span><span class="pln">

</span><span class="kwd">void</span><span class="pln"> ledFadeToBeat</span><span class="pun">(</span><span class="kwd">int</span><span class="pln"> BPM</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  </span><span class="kwd">static</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> i </span><span class="pun">=</span><span class="pln"> </span><span class="lit">100</span><span class="pun">;</span><span class="pln">
           </span><span class="com">// Set LED fade value</span><span class="pln">
  </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">BPM </span><span class="pun"><</span><span class="pln"> </span><span class="lit">50</span><span class="pun">){</span><span class="pln">
    i</span><span class="pun">+=</span><span class="lit">1</span><span class="pun">;</span><span class="pln">
      </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">i </span><span class="pun">>=</span><span class="pln"> </span><span class="lit">201</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
        i </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
    </span><span class="pun">}</span><span class="pln">
    fadeRate </span><span class="pun">=</span><span class="pln"> brightnessVal</span><span class="pun">[</span><span class="pln">i</span><span class="pun">];</span><span class="pln">
    fadeRate </span><span class="pun">=</span><span class="pln"> constrain</span><span class="pun">(</span><span class="pln">fadeRate</span><span class="pun">,</span><span class="lit">0</span><span class="pun">,</span><span class="lit">255</span><span class="pun">);</span><span class="pln">   </span><span class="com">// Keep LED fade value from going into negative numbers</span><span class="pln">
    setStrip</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="lit">0</span><span class="pun">,</span><span class="pln">fadeRate</span><span class="pun">,</span><span class="pln"> BPM</span><span class="pun">);</span><span class="pln">
  </span><span class="pun">}</span><span class="pln">
  </span><span class="kwd">else</span><span class="pln"> </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">BPM </span><span class="pun">>=</span><span class="pln"> </span><span class="lit">50</span><span class="pln"> </span><span class="kwd">and</span><span class="pln"> BPM </span><span class="pun"><</span><span class="pln"> </span><span class="lit">80</span><span class="pun">){</span><span class="pln"> </span><span class="com">// setting BPM thresholds to set pulsing speed </span><span class="pln">
    i</span><span class="pun">+=</span><span class="lit">2</span><span class="pun">;</span><span class="pln">
    </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">i </span><span class="pun">>=</span><span class="pln"> </span><span class="lit">201</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
       i </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
    </span><span class="pun">}</span><span class="pln">
    fadeRate </span><span class="pun">=</span><span class="pln"> brightnessVal</span><span class="pun">[</span><span class="pln">i</span><span class="pun">];</span><span class="pln">
    fadeRate </span><span class="pun">=</span><span class="pln"> constrain</span><span class="pun">(</span><span class="pln">fadeRate</span><span class="pun">,</span><span class="lit">0</span><span class="pun">,</span><span class="lit">255</span><span class="pun">);</span><span class="pln">   </span><span class="com">// Keep LED fade value from going into negative numbers</span><span class="pln">
    setStrip</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="lit">0</span><span class="pun">,</span><span class="pln">fadeRate</span><span class="pun">,</span><span class="pln"> BPM</span><span class="pun">);</span><span class="pln">
  </span><span class="pun">}</span><span class="pln">
  </span><span class="kwd">else</span><span class="pln"> </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">BPM </span><span class="pun">>=</span><span class="pln"> </span><span class="lit">80</span><span class="pln"> </span><span class="kwd">and</span><span class="pln"> BPM </span><span class="pun"><</span><span class="pln"> </span><span class="lit">100</span><span class="pun">){</span><span class="pln">
    i</span><span class="pun">+=</span><span class="lit">3</span><span class="pun">;</span><span class="pln">
    </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">i </span><span class="pun">>=</span><span class="pln"> </span><span class="lit">201</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
       i </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
    </span><span class="pun">}</span><span class="pln">
    fadeRate </span><span class="pun">=</span><span class="pln"> brightnessVal</span><span class="pun">[</span><span class="pln">i</span><span class="pun">];</span><span class="pln">
    fadeRate </span><span class="pun">=</span><span class="pln"> constrain</span><span class="pun">(</span><span class="pln">fadeRate</span><span class="pun">,</span><span class="lit">0</span><span class="pun">,</span><span class="lit">255</span><span class="pun">);</span><span class="pln">   </span><span class="com">// Keep LED fade value from going into negative numbers</span><span class="pln">
    setStrip</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="lit">0</span><span class="pun">,</span><span class="pln">fadeRate</span><span class="pun">,</span><span class="pln"> BPM</span><span class="pun">);</span><span class="pln">
  </span><span class="pun">}</span><span class="pln">
  </span><span class="kwd">else</span><span class="pln"> </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">BPM </span><span class="pun">>=</span><span class="pln"> </span><span class="lit">100</span><span class="pln"> </span><span class="kwd">and</span><span class="pln"> BPM </span><span class="pun"><</span><span class="pln"> </span><span class="lit">120</span><span class="pun">){</span><span class="pln">
    i</span><span class="pun">+=</span><span class="lit">4</span><span class="pun">;</span><span class="pln">
    </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">i </span><span class="pun">>=</span><span class="pln"> </span><span class="lit">201</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
       i </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
    </span><span class="pun">}</span><span class="pln">
    fadeRate </span><span class="pun">=</span><span class="pln"> brightnessVal</span><span class="pun">[</span><span class="pln">i</span><span class="pun">];</span><span class="pln">
    fadeRate </span><span class="pun">=</span><span class="pln"> constrain</span><span class="pun">(</span><span class="pln">fadeRate</span><span class="pun">,</span><span class="lit">0</span><span class="pun">,</span><span class="lit">255</span><span class="pun">);</span><span class="pln">   </span><span class="com">// Keep LED fade value from going into negative numbers</span><span class="pln">
    setStrip</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="lit">0</span><span class="pun">,</span><span class="pln">fadeRate</span><span class="pun">,</span><span class="pln"> BPM</span><span class="pun">);</span><span class="pln">
  </span><span class="pun">}</span><span class="pln">
  </span><span class="kwd">else</span><span class="pln"> </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">BPM </span><span class="pun">>=</span><span class="pln"> </span><span class="lit">120</span><span class="pln"> </span><span class="kwd">and</span><span class="pln"> BPM </span><span class="pun"><</span><span class="pln"> </span><span class="lit">150</span><span class="pun">){</span><span class="pln">
    i</span><span class="pun">+=</span><span class="lit">5</span><span class="pun">;</span><span class="pln">
    </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">i </span><span class="pun">>=</span><span class="pln"> </span><span class="lit">201</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
       i </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
    </span><span class="pun">}</span><span class="pln">
    fadeRate </span><span class="pun">=</span><span class="pln"> brightnessVal</span><span class="pun">[</span><span class="pln">i</span><span class="pun">];</span><span class="pln">
    fadeRate </span><span class="pun">=</span><span class="pln"> constrain</span><span class="pun">(</span><span class="pln">fadeRate</span><span class="pun">,</span><span class="lit">0</span><span class="pun">,</span><span class="lit">255</span><span class="pun">);</span><span class="pln">   </span><span class="com">// Keep LED fade value from going into negative numbers</span><span class="pln">
    setStrip</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="lit">0</span><span class="pun">,</span><span class="pln">fadeRate</span><span class="pun">,</span><span class="pln"> BPM</span><span class="pun">);</span><span class="pln">
  </span><span class="pun">}</span><span class="pln">
  </span><span class="kwd">else</span><span class="pun">{</span><span class="pln">
    </span><span class="kwd">for</span><span class="pln"> </span><span class="pun">(</span><span class="kwd">int</span><span class="pln"> x</span><span class="pun">=</span><span class="lit">0</span><span class="pun">;</span><span class="pln"> x </span><span class="pun"><</span><span class="pln"> NUMPIXELS</span><span class="pun">;</span><span class="pln"> x</span><span class="pun">++)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">  </span><span class="com">// Initialize all pixels to 'off'</span><span class="pln">
       strip</span><span class="pun">.</span><span class="pln">setPixelColor</span><span class="pun">(</span><span class="pln">x</span><span class="pun">,</span><span class="pln"> strip</span><span class="pun">.</span><span class="typ">Color</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">));</span><span class="pln">
    </span><span class="pun">}</span><span class="pln">
    strip</span><span class="pun">.</span><span class="pln">show</span><span class="pun">();</span><span class="pln">
    i</span><span class="pun">=</span><span class="lit">0</span><span class="pun">;</span><span class="pln">
  </span><span class="pun">}</span><span class="pln">
</span><span class="com">//  Serial.print("i=");</span><span class="pln">
</span><span class="com">//  Serial.println(i);</span><span class="pln">
</span><span class="com">//    sendDataSerial('R',fadeRate);</span><span class="pln">
</span><span class="pun">}</span><span class="pln">

</span><span class="kwd">void</span><span class="pln"> sendDataSerial</span><span class="pun">(</span><span class="kwd">char</span><span class="pln"> symbol</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> data </span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
</span><span class="com">//    Serial.print(symbol);                // symbol prefix tells Processing what type of data is coming</span><span class="pln">
</span><span class="com">//    Serial.println(data);                // the data to send culminating in a carriage return</span><span class="pln">
</span><span class="pun">}</span><span class="pln">

</span><span class="kwd">void</span><span class="pln"> setStrip</span><span class="pun">(</span><span class="kwd">int</span><span class="pln"> r</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> g</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> b</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> BPM</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">     </span><span class="com">// Set the strip to one color intensity (blue)</span><span class="pln">
  </span><span class="kwd">for</span><span class="pln"> </span><span class="pun">(</span><span class="kwd">int</span><span class="pln"> x</span><span class="pun">=</span><span class="lit">0</span><span class="pun">;</span><span class="pln"> x </span><span class="pun"><</span><span class="pln"> NUMPIXELS</span><span class="pun">;</span><span class="pln"> x</span><span class="pun">++)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
    strip</span><span class="pun">.</span><span class="pln">setPixelColor</span><span class="pun">(</span><span class="pln">x</span><span class="pun">,</span><span class="pln"> strip</span><span class="pun">.</span><span class="typ">Color</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> b</span><span class="pun">));</span><span class="pln">
  </span><span class="pun">}</span><span class="pln">
   strip</span><span class="pun">.</span><span class="pln">show</span><span class="pun">();</span><span class="pln">
</span><span class="pun">}</span><span class="pln">

</span><span class="com">/*
  sending the 10 most recent bpm values to receiver

*/</span><span class="pln">
</span><span class="kwd">void</span><span class="pln"> send</span><span class="pun">(</span><span class="kwd">int</span><span class="pln"> bpmAvg</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="com">// function for radio </span><span class="pln">

  </span><span class="com">// shift every BPM value to the right for the new bpmAvg</span><span class="pln">
  </span><span class="kwd">for</span><span class="pln"> </span><span class="pun">(</span><span class="kwd">int</span><span class="pln"> i</span><span class="pun">=</span><span class="lit">0</span><span class="pun">;</span><span class="pln"> i</span><span class="pun"><</span><span class="lit">9</span><span class="pun">;</span><span class="pln"> i</span><span class="pun">++){</span><span class="pln">
    dailyBPM</span><span class="pun">[</span><span class="pln">i</span><span class="pun">+</span><span class="lit">1</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> dailyBPM</span><span class="pun">[</span><span class="pln">i</span><span class="pun">];</span><span class="pln">
  </span><span class="pun">}</span><span class="pln">
  dailyBPM</span><span class="pun">[</span><span class="lit">0</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> bpmAvg</span><span class="pun">;</span><span class="pln"> </span><span class="com">//putting newest bpmAvg value at the front of array</span><span class="pln">

  </span><span class="kwd">bool</span><span class="pln"> rslt </span><span class="pun">=</span><span class="pln"> radio</span><span class="pun">.</span><span class="pln">write</span><span class="pun">(</span><span class="pln"> </span><span class="pun">&</span><span class="pln">dailyBPM</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">sizeof</span><span class="pun">(</span><span class="pln">dailyBPM</span><span class="pun">)</span><span class="pln"> </span><span class="pun">);</span><span class="pln">
        </span><span class="com">// Always use sizeof() as it gives the size as the number of bytes.</span><span class="pln">
        </span><span class="com">// For example if dataToSend was an int sizeof() would correctly return 2</span><span class="pln">

    </span><span class="typ">Serial</span><span class="pun">.</span><span class="kwd">print</span><span class="pun">(</span><span class="str">"Data Sent "</span><span class="pun">);</span><span class="pln">
    </span><span class="kwd">for</span><span class="pln"> </span><span class="pun">(</span><span class="kwd">int</span><span class="pln"> x </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln"> x </span><span class="pun"><</span><span class="pln"> </span><span class="pun">(</span><span class="kwd">sizeof</span><span class="pun">(</span><span class="pln">dailyBPM</span><span class="pun">)</span><span class="pln"> </span><span class="pun">/</span><span class="pln"> </span><span class="kwd">sizeof</span><span class="pun">(</span><span class="pln">dailyBPM</span><span class="pun">[</span><span class="lit">0</span><span class="pun">]));</span><span class="pln"> x</span><span class="pun">++)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
      </span><span class="typ">Serial</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="pln">dailyBPM</span><span class="pun">[</span><span class="pln">x</span><span class="pun">]);</span><span class="pln">
    </span><span class="pun">}</span><span class="pln">
    </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">rslt</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
        </span><span class="typ">Serial</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"  Acknowledge received"</span><span class="pun">);</span><span class="pln">
        memset</span><span class="pun">(</span><span class="pln">dailyBPM</span><span class="pun">,</span><span class="pln"> </span><span class="pun">-</span><span class="lit">1</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">sizeof</span><span class="pun">(</span><span class="pln">dailyBPM</span><span class="pun">));</span><span class="pln">

        </span><span class="com">// for (int x = 0; x < sizeof(dailyBPM) / sizeof(dailyBPM[0]); x++)</span><span class="pln">
        </span><span class="com">// updateMessage();</span><span class="pln">
    </span><span class="pun">}</span><span class="pln">

    </span><span class="kwd">else</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
        </span><span class="typ">Serial</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"  Tx failed"</span><span class="pun">);</span><span class="pln">
    </span><span class="pun">}</span><span class="pln">
</span><span class="pun">}</span>

Code for the dock:

  1. <span class="com">#include</span><span class="pln"> </span><span class="str"><Adafruit_GFX.h></span><span class="pln"> </span><span class="com">// Core graphics library</span><span class="pln">
  2. </span><span class="com">#include</span><span class="pln"> </span><span class="str"><Adafruit_ST7735.h></span><span class="pln"> </span><span class="com">// Hardware-specific library for ST7735</span><span class="pln">
  3. </span><span class="com">#include</span><span class="pln"> </span><span class="str"><Adafruit_ST7789.h></span><span class="pln"> </span><span class="com">// Hardware-specific library for ST7789</span><span class="pln">
  4. </span><span class="com">#include</span><span class="pln"> </span><span class="str"><SPI.h></span><span class="pln">
  5. </span><span class="com">#ifdef</span><span class="pln"> ADAFRUIT_HALLOWING
  6. </span><span class="com">#define</span><span class="pln"> TFT_CS </span><span class="lit">39</span><span class="pln"> </span><span class="com">// Hallowing display control pins: chip select</span><span class="pln">
  7. </span><span class="com">#define</span><span class="pln"> TFT_RST </span><span class="lit">37</span><span class="pln"> </span><span class="com">// Display reset</span><span class="pln">
  8. </span><span class="com">#define</span><span class="pln"> TFT_DC </span><span class="lit">38</span><span class="pln"> </span><span class="com">// Display data/command select</span><span class="pln">
  9. </span><span class="com">#define</span><span class="pln"> TFT_BACKLIGHT </span><span class="lit">7</span><span class="pln"> </span><span class="com">// Display backlight pin</span><span class="pln">
  10. </span><span class="com">#else</span><span class="pln">
  11. </span><span class="com">#define</span><span class="pln"> TFT_CS </span><span class="lit">10</span><span class="pln">
  12. </span><span class="com">#define</span><span class="pln"> TFT_RST </span><span class="lit">9</span><span class="pln"> </span><span class="com">// Or set to -1 and connect to Arduino RESET pin</span><span class="pln">
  13. </span><span class="com">#define</span><span class="pln"> TFT_DC </span><span class="lit">8</span><span class="pln">
  14. </span><span class="com">#endif</span><span class="pln">
  15. </span><span class="typ">Adafruit_ST7735</span><span class="pln"> tft </span><span class="pun">=</span><span class="pln"> </span><span class="typ">Adafruit_ST7735</span><span class="pun">(</span><span class="pln">TFT_CS</span><span class="pun">,</span><span class="pln"> TFT_DC</span><span class="pun">,</span><span class="pln"> TFT_RST</span><span class="pun">);</span><span class="pln">
  16. </span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> CHARGE_PIN1 </span><span class="pun">=</span><span class="pln"> A1</span><span class="pun">;</span><span class="pln"> </span><span class="com">// display turns on when contact is made from the device to the dock</span><span class="pln">
  17. </span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> CHARGE_PIN2 </span><span class="pun">=</span><span class="pln"> A2</span><span class="pun">;</span><span class="pln">
  18. </span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> CHARGE_TOLERANCE </span><span class="pun">=</span><span class="pln"> </span><span class="lit">20</span><span class="pun">;</span><span class="pln">
  19. </span><span class="kwd">void</span><span class="pln"> setup</span><span class="pun">(</span><span class="kwd">void</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  20. </span><span class="com">#ifdef</span><span class="pln"> ADAFRUIT_HALLOWING
  21. tft</span><span class="pun">.</span><span class="pln">initR</span><span class="pun">(</span><span class="pln">INITR_HALLOWING</span><span class="pun">);</span><span class="pln"> </span><span class="com">// Initialize HalloWing-oriented screen</span><span class="pln">
  22. pinMode</span><span class="pun">(</span><span class="pln">TFT_BACKLIGHT</span><span class="pun">,</span><span class="pln"> OUTPUT</span><span class="pun">);</span><span class="pln">
  23. digitalWrite</span><span class="pun">(</span><span class="pln">TFT_BACKLIGHT</span><span class="pun">,</span><span class="pln"> HIGH</span><span class="pun">);</span><span class="pln"> </span><span class="com">// Backlight on</span><span class="pln">
  24. </span><span class="com">#else</span><span class="pln">
  25. </span><span class="com">// Use this initializer if using a 1.8" TFT screen:</span><span class="pln">
  26. tft</span><span class="pun">.</span><span class="pln">initR</span><span class="pun">(</span><span class="pln">INITR_BLACKTAB</span><span class="pun">);</span><span class="pln"> </span><span class="com">// Init ST7735S chip, black tab</span><span class="pln">
  27. </span><span class="com">#endif</span><span class="pln">
  28. tft</span><span class="pun">.</span><span class="pln">setRotation</span><span class="pun">(</span><span class="lit">1</span><span class="pun">);</span><span class="pln"> </span><span class="com">// rotate the screen to horizontal </span><span class="pln">
  29. pinMode</span><span class="pun">(</span><span class="pln">CHARGE_PIN1</span><span class="pun">,</span><span class="pln"> INPUT</span><span class="pun">);</span><span class="pln">
  30. pinMode</span><span class="pun">(</span><span class="pln">CHARGE_PIN2</span><span class="pun">,</span><span class="pln"> INPUT</span><span class="pun">);</span><span class="pln">
  31. </span><span class="typ">Serial</span><span class="pun">.</span><span class="kwd">begin</span><span class="pun">(</span><span class="lit">9600</span><span class="pun">);</span><span class="pln">
  32. testfillcircles</span><span class="pun">(</span><span class="lit">10</span><span class="pun">,</span><span class="pln"> ST77XX_BLUE</span><span class="pun">);</span><span class="pln">
  33. testdrawcircles</span><span class="pun">(</span><span class="lit">10</span><span class="pun">,</span><span class="pln"> ST77XX_WHITE</span><span class="pun">);</span><span class="pln">
  34. </span><span class="pun">}</span><span class="pln">
  35. </span><span class="kwd">void</span><span class="pln"> loop</span><span class="pun">()</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  36. </span><span class="kwd">static</span><span class="pln"> </span><span class="kwd">bool</span><span class="pln"> plugged </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">;</span><span class="pln">
  37. </span><span class="kwd">int</span><span class="pln"> chargeRead1 </span><span class="pun">=</span><span class="pln"> analogRead</span><span class="pun">(</span><span class="pln">CHARGE_PIN1</span><span class="pun">);</span><span class="pln"> </span><span class="com">// reading if contact has been made </span><span class="pln">
  38. </span><span class="kwd">int</span><span class="pln"> chargeRead2 </span><span class="pun">=</span><span class="pln"> analogRead</span><span class="pun">(</span><span class="pln">CHARGE_PIN2</span><span class="pun">);</span><span class="pln">
  39. </span><span class="com">// Serial.println(chargeRead1);</span><span class="pln">
  40. </span><span class="com">// Serial.println(chargeRead2);</span><span class="pln">
  41. </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">((</span><span class="pln">chargeRead1 </span><span class="pun">-</span><span class="pln"> CHARGE_TOLERANCE </span><span class="pun"><=</span><span class="pln"> chargeRead2</span><span class="pun">)</span><span class="pln"> </span><span class="kwd">and</span><span class="pln"> </span><span class="com">// portable device not plugged in </span><span class="pln">
  42. </span><span class="pun">(</span><span class="pln">chargeRead2 </span><span class="pun"><=</span><span class="pln"> chargeRead1 </span><span class="pun">+</span><span class="pln"> CHARGE_TOLERANCE</span><span class="pun">))</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  43. plugged </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">;</span><span class="pln">
  44. tft</span><span class="pun">.</span><span class="pln">fillScreen</span><span class="pun">(</span><span class="pln">ST77XX_BLACK</span><span class="pun">);</span><span class="pln">
  45. </span><span class="pun">}</span><span class="pln">
  46. </span><span class="kwd">else</span><span class="pln"> </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">plugged </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="com">// this condition fires once we plug in </span><span class="pln">
  47. tftPrintTest</span><span class="pun">();</span><span class="pln">
  48. plugged </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">;</span><span class="pln"> </span><span class="com">// portable device marked as "plugged in" now</span><span class="pln">
  49. </span><span class="pun">}</span><span class="pln">
  50. delay</span><span class="pun">(</span><span class="lit">500</span><span class="pun">);</span><span class="pln">
  51. </span><span class="pun">}</span><span class="pln">
  52. </span><span class="kwd">void</span><span class="pln"> tftPrintTest</span><span class="pun">()</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="com">// the content of the screens </span><span class="pln">
  53. tft</span><span class="pun">.</span><span class="pln">fillScreen</span><span class="pun">(</span><span class="pln">ST77XX_MAGENTA</span><span class="pun">);</span><span class="pln">
  54. tft</span><span class="pun">.</span><span class="pln">setTextColor</span><span class="pun">(</span><span class="pln">ST77XX_WHITE</span><span class="pun">);</span><span class="pln">
  55. tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">30</span><span class="pun">);</span><span class="pln">
  56. tft</span><span class="pun">.</span><span class="pln">setTextSize</span><span class="pun">(</span><span class="lit">3</span><span class="pun">);</span><span class="pln">
  57. tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"WELCOME"</span><span class="pun">);</span><span class="pln">
  58. tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">60</span><span class="pun">);</span><span class="pln">
  59. tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"HOME"</span><span class="pun">);</span><span class="pln">
  60. tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">90</span><span class="pun">);</span><span class="pln">
  61. tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"ELINOR!"</span><span class="pun">);</span><span class="pln">
  62. delay</span><span class="pun">(</span><span class="lit">3000</span><span class="pun">);</span><span class="pln">
  63. tft</span><span class="pun">.</span><span class="pln">setTextSize</span><span class="pun">(</span><span class="lit">1</span><span class="pun">);</span><span class="pln">
  64. tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">20</span><span class="pun">);</span><span class="pln">
  65. tft</span><span class="pun">.</span><span class="pln">fillScreen</span><span class="pun">(</span><span class="pln">ST77XX_BLACK</span><span class="pun">);</span><span class="pln">
  66. tft</span><span class="pun">.</span><span class="pln">setTextColor</span><span class="pun">(</span><span class="pln">ST77XX_WHITE</span><span class="pun">);</span><span class="pln">
  67. tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"Hello Elinor!"</span><span class="pun">);</span><span class="pln">
  68. tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">40</span><span class="pun">);</span><span class="pln">
  69. tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"Hope you are having"</span><span class="pun">);</span><span class="pln">
  70. tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">60</span><span class="pun">);</span><span class="pln">
  71. tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"a great day."</span><span class="pun">);</span><span class="pln">
  72. delay</span><span class="pun">(</span><span class="lit">5000</span><span class="pun">);</span><span class="pln">
  73. tft</span><span class="pun">.</span><span class="pln">fillScreen</span><span class="pun">(</span><span class="pln">ST77XX_BLUE</span><span class="pun">);</span><span class="pln">
  74. tft</span><span class="pun">.</span><span class="pln">setTextColor</span><span class="pun">(</span><span class="pln">ST77XX_WHITE</span><span class="pun">);</span><span class="pln">
  75. tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">10</span><span class="pun">);</span><span class="pln">
  76. tft</span><span class="pun">.</span><span class="pln">setTextSize</span><span class="pun">(</span><span class="lit">2</span><span class="pun">);</span><span class="pln">
  77. tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"Here are some"</span><span class="pun">);</span><span class="pln">
  78. tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">30</span><span class="pun">);</span><span class="pln">
  79. tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"breathing"</span><span class="pun">);</span><span class="pln">
  80. tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">50</span><span class="pun">);</span><span class="pln">
  81. tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"tips for you!"</span><span class="pun">);</span><span class="pln">
  82. delay</span><span class="pun">(</span><span class="lit">3000</span><span class="pun">);</span><span class="pln">
  83. tft</span><span class="pun">.</span><span class="pln">fillScreen</span><span class="pun">(</span><span class="pln">ST77XX_BLUE</span><span class="pun">);</span><span class="pln">
  84. tft</span><span class="pun">.</span><span class="pln">setTextColor</span><span class="pun">(</span><span class="pln">ST77XX_WHITE</span><span class="pun">);</span><span class="pln">
  85. tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">10</span><span class="pun">);</span><span class="pln">
  86. tft</span><span class="pun">.</span><span class="pln">setTextSize</span><span class="pun">(</span><span class="lit">2</span><span class="pun">);</span><span class="pln">
  87. tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"First, take a"</span><span class="pun">);</span><span class="pln">
  88. tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">30</span><span class="pun">);</span><span class="pln">
  89. tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"long, slow"</span><span class="pun">);</span><span class="pln">
  90. tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">55</span><span class="pun">);</span><span class="pln">
  91. tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"INHALE."</span><span class="pun">);</span><span class="pln">
  92. delay</span><span class="pun">(</span><span class="lit">3000</span><span class="pun">);</span><span class="pln">
  93. tft</span><span class="pun">.</span><span class="pln">fillScreen</span><span class="pun">(</span><span class="pln">ST77XX_BLUE</span><span class="pun">);</span><span class="pln">
  94. tft</span><span class="pun">.</span><span class="pln">setTextColor</span><span class="pun">(</span><span class="pln">ST77XX_WHITE</span><span class="pun">);</span><span class="pln">
  95. tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">10</span><span class="pun">);</span><span class="pln">
  96. tft</span><span class="pun">.</span><span class="pln">setTextSize</span><span class="pun">(</span><span class="lit">2</span><span class="pun">);</span><span class="pln">
  97. tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"Next, a quick"</span><span class="pun">);</span><span class="pln">
  98. tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">30</span><span class="pun">);</span><span class="pln">
  99. tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"and powerful"</span><span class="pun">);</span><span class="pln">
  100. tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">55</span><span class="pun">);</span><span class="pln">
  101. tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"EXHALE."</span><span class="pun">);</span><span class="pln">
  102. delay</span><span class="pun">(</span><span class="lit">3000</span><span class="pun">);</span><span class="pln">
  103. tft</span><span class="pun">.</span><span class="pln">fillScreen</span><span class="pun">(</span><span class="pln">ST77XX_BLUE</span><span class="pun">);</span><span class="pln">
  104. tft</span><span class="pun">.</span><span class="pln">setTextColor</span><span class="pun">(</span><span class="pln">ST77XX_WHITE</span><span class="pun">);</span><span class="pln">
  105. tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">10</span><span class="pun">);</span><span class="pln">
  106. tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"Take a total"</span><span class="pun">);</span><span class="pln">
  107. tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">30</span><span class="pun">);</span><span class="pln">
  108. tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"of 10 breaths"</span><span class="pun">);</span><span class="pln">
  109. delay</span><span class="pun">(</span><span class="lit">3000</span><span class="pun">);</span><span class="pln">
  110. tft</span><span class="pun">.</span><span class="pln">fillScreen</span><span class="pun">(</span><span class="pln">ST77XX_WHITE</span><span class="pun">);</span><span class="pln">
  111. testfillcircles</span><span class="pun">(</span><span class="lit">10</span><span class="pun">,</span><span class="pln"> ST77XX_BLUE</span><span class="pun">);</span><span class="pln">
  112. testdrawcircles</span><span class="pun">(</span><span class="lit">10</span><span class="pun">,</span><span class="pln"> ST77XX_WHITE</span><span class="pun">);</span><span class="pln">
  113. delay</span><span class="pun">(</span><span class="lit">4000</span><span class="pun">);</span><span class="pln">
  114. testlines</span><span class="pun">(</span><span class="pln">ST77XX_YELLOW</span><span class="pun">);</span><span class="pln">
  115. delay</span><span class="pun">(</span><span class="lit">2000</span><span class="pun">);</span><span class="pln">
  116. testfastlines</span><span class="pun">(</span><span class="pln">ST77XX_RED</span><span class="pun">,</span><span class="pln"> ST77XX_BLUE</span><span class="pun">);</span><span class="pln">
  117. delay</span><span class="pun">(</span><span class="lit">2000</span><span class="pun">);</span><span class="pln">
  118. tft</span><span class="pun">.</span><span class="pln">fillScreen</span><span class="pun">(</span><span class="pln">ST77XX_GREEN</span><span class="pun">);</span><span class="pln">
  119. tft</span><span class="pun">.</span><span class="pln">setTextColor</span><span class="pun">(</span><span class="pln">ST77XX_WHITE</span><span class="pun">);</span><span class="pln">
  120. tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">10</span><span class="pun">);</span><span class="pln">
  121. tft</span><span class="pun">.</span><span class="pln">setTextSize</span><span class="pun">(</span><span class="lit">2</span><span class="pun">);</span><span class="pln">
  122. tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"Here's a"</span><span class="pun">);</span><span class="pln">
  123. tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">30</span><span class="pun">);</span><span class="pln">
  124. tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"tip for you!"</span><span class="pun">);</span><span class="pln">
  125. delay</span><span class="pun">(</span><span class="lit">3000</span><span class="pun">);</span><span class="pln">
  126. tft</span><span class="pun">.</span><span class="pln">fillScreen</span><span class="pun">(</span><span class="pln">ST77XX_GREEN</span><span class="pun">);</span><span class="pln">
  127. tft</span><span class="pun">.</span><span class="pln">setTextColor</span><span class="pun">(</span><span class="pln">ST77XX_WHITE</span><span class="pun">);</span><span class="pln">
  128. tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">10</span><span class="pun">);</span><span class="pln">
  129. tft</span><span class="pun">.</span><span class="pln">setTextSize</span><span class="pun">(</span><span class="lit">2</span><span class="pun">);</span><span class="pln">
  130. tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"Deep breaths"</span><span class="pun">);</span><span class="pln">
  131. tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">30</span><span class="pun">);</span><span class="pln">
  132. tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"increase your"</span><span class="pun">);</span><span class="pln">
  133. tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">50</span><span class="pun">);</span><span class="pln">
  134. tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"oxygen flow."</span><span class="pun">);</span><span class="pln">
  135. delay</span><span class="pun">(</span><span class="lit">2000</span><span class="pun">);</span><span class="pln">
  136. tft</span><span class="pun">.</span><span class="pln">fillScreen</span><span class="pun">(</span><span class="pln">ST77XX_GREEN</span><span class="pun">);</span><span class="pln">
  137. tft</span><span class="pun">.</span><span class="pln">setTextColor</span><span class="pun">(</span><span class="pln">ST77XX_WHITE</span><span class="pun">);</span><span class="pln">
  138. tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">10</span><span class="pun">);</span><span class="pln">
  139. tft</span><span class="pun">.</span><span class="pln">setTextSize</span><span class="pun">(</span><span class="lit">2</span><span class="pun">);</span><span class="pln">
  140. tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"Also, it"</span><span class="pun">);</span><span class="pln">
  141. tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">30</span><span class="pun">);</span><span class="pln">
  142. tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"promotes a"</span><span class="pun">);</span><span class="pln">
  143. tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">50</span><span class="pun">);</span><span class="pln">
  144. tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"state of"</span><span class="pun">);</span><span class="pln">
  145. tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">70</span><span class="pun">);</span><span class="pln">
  146. tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"CALMNESS."</span><span class="pun">);</span><span class="pln">
  147. delay</span><span class="pun">(</span><span class="lit">5000</span><span class="pun">);</span><span class="pln">
  148. tft</span><span class="pun">.</span><span class="pln">fillScreen</span><span class="pun">(</span><span class="pln">ST77XX_WHITE</span><span class="pun">);</span><span class="pln">
  149. testfillcircles</span><span class="pun">(</span><span class="lit">10</span><span class="pun">,</span><span class="pln"> ST77XX_BLUE</span><span class="pun">);</span><span class="pln">
  150. testdrawcircles</span><span class="pun">(</span><span class="lit">10</span><span class="pun">,</span><span class="pln"> ST77XX_WHITE</span><span class="pun">);</span><span class="pln">
  151. </span><span class="pun">}</span><span class="pln">
  152. </span><span class="kwd">void</span><span class="pln"> testfillcircles</span><span class="pun">(</span><span class="typ">uint8_t</span><span class="pln"> radius</span><span class="pun">,</span><span class="pln"> </span><span class="typ">uint16_t</span><span class="pln"> color</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="com">//graphics for elinor to view while breathing</span><span class="pln">
  153. </span><span class="kwd">for</span><span class="pln"> </span><span class="pun">(</span><span class="typ">int16_t</span><span class="pln"> x</span><span class="pun">=</span><span class="pln">radius</span><span class="pun">;</span><span class="pln"> x </span><span class="pun"><</span><span class="pln"> tft</span><span class="pun">.</span><span class="pln">width</span><span class="pun">();</span><span class="pln"> x</span><span class="pun">+=</span><span class="pln">radius</span><span class="pun">*</span><span class="lit">2</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  154. </span><span class="kwd">for</span><span class="pln"> </span><span class="pun">(</span><span class="typ">int16_t</span><span class="pln"> y</span><span class="pun">=</span><span class="pln">radius</span><span class="pun">;</span><span class="pln"> y </span><span class="pun"><</span><span class="pln"> tft</span><span class="pun">.</span><span class="pln">height</span><span class="pun">();</span><span class="pln"> y</span><span class="pun">+=</span><span class="pln">radius</span><span class="pun">*</span><span class="lit">2</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  155. tft</span><span class="pun">.</span><span class="pln">fillCircle</span><span class="pun">(</span><span class="pln">x</span><span class="pun">,</span><span class="pln"> y</span><span class="pun">,</span><span class="pln"> radius</span><span class="pun">,</span><span class="pln"> color</span><span class="pun">);</span><span class="pln">
  156. </span><span class="pun">}</span><span class="pln">
  157. </span><span class="pun">}</span><span class="pln">
  158. </span><span class="pun">}</span><span class="pln">
  159. </span><span class="kwd">void</span><span class="pln"> testdrawcircles</span><span class="pun">(</span><span class="typ">uint8_t</span><span class="pln"> radius</span><span class="pun">,</span><span class="pln"> </span><span class="typ">uint16_t</span><span class="pln"> color</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  160. </span><span class="kwd">for</span><span class="pln"> </span><span class="pun">(</span><span class="typ">int16_t</span><span class="pln"> x</span><span class="pun">=</span><span class="lit">0</span><span class="pun">;</span><span class="pln"> x </span><span class="pun"><</span><span class="pln"> tft</span><span class="pun">.</span><span class="pln">width</span><span class="pun">()+</span><span class="pln">radius</span><span class="pun">;</span><span class="pln"> x</span><span class="pun">+=</span><span class="pln">radius</span><span class="pun">*</span><span class="lit">2</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  161. </span><span class="kwd">for</span><span class="pln"> </span><span class="pun">(</span><span class="typ">int16_t</span><span class="pln"> y</span><span class="pun">=</span><span class="lit">0</span><span class="pun">;</span><span class="pln"> y </span><span class="pun"><</span><span class="pln"> tft</span><span class="pun">.</span><span class="pln">height</span><span class="pun">()+</span><span class="pln">radius</span><span class="pun">;</span><span class="pln"> y</span><span class="pun">+=</span><span class="pln">radius</span><span class="pun">*</span><span class="lit">2</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  162. tft</span><span class="pun">.</span><span class="pln">drawCircle</span><span class="pun">(</span><span class="pln">x</span><span class="pun">,</span><span class="pln"> y</span><span class="pun">,</span><span class="pln"> radius</span><span class="pun">,</span><span class="pln"> color</span><span class="pun">);</span><span class="pln">
  163. </span><span class="pun">}</span><span class="pln">
  164. </span><span class="pun">}</span><span class="pln">
  165. </span><span class="pun">}</span><span class="pln">
  166. </span><span class="kwd">void</span><span class="pln"> testlines</span><span class="pun">(</span><span class="typ">uint16_t</span><span class="pln"> color</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  167. tft</span><span class="pun">.</span><span class="pln">fillScreen</span><span class="pun">(</span><span class="pln">ST77XX_BLACK</span><span class="pun">);</span><span class="pln">
  168. </span><span class="kwd">for</span><span class="pln"> </span><span class="pun">(</span><span class="typ">int16_t</span><span class="pln"> x</span><span class="pun">=</span><span class="lit">0</span><span class="pun">;</span><span class="pln"> x </span><span class="pun"><</span><span class="pln"> tft</span><span class="pun">.</span><span class="pln">width</span><span class="pun">();</span><span class="pln"> x</span><span class="pun">+=</span><span class="lit">6</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  169. tft</span><span class="pun">.</span><span class="pln">drawLine</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> x</span><span class="pun">,</span><span class="pln"> tft</span><span class="pun">.</span><span class="pln">height</span><span class="pun">()-</span><span class="lit">1</span><span class="pun">,</span><span class="pln"> color</span><span class="pun">);</span><span class="pln">
  170. delay</span><span class="pun">(</span><span class="lit">0</span><span class="pun">);</span><span class="pln">
  171. </span><span class="pun">}</span><span class="pln">
  172. </span><span class="kwd">for</span><span class="pln"> </span><span class="pun">(</span><span class="typ">int16_t</span><span class="pln"> y</span><span class="pun">=</span><span class="lit">0</span><span class="pun">;</span><span class="pln"> y </span><span class="pun"><</span><span class="pln"> tft</span><span class="pun">.</span><span class="pln">height</span><span class="pun">();</span><span class="pln"> y</span><span class="pun">+=</span><span class="lit">6</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  173. tft</span><span class="pun">.</span><span class="pln">drawLine</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> tft</span><span class="pun">.</span><span class="pln">width</span><span class="pun">()-</span><span class="lit">1</span><span class="pun">,</span><span class="pln"> y</span><span class="pun">,</span><span class="pln"> color</span><span class="pun">);</span><span class="pln">
  174. delay</span><span class="pun">(</span><span class="lit">0</span><span class="pun">);</span><span class="pln">
  175. </span><span class="pun">}</span><span class="pln">
  176. tft</span><span class="pun">.</span><span class="pln">fillScreen</span><span class="pun">(</span><span class="pln">ST77XX_BLACK</span><span class="pun">);</span><span class="pln">
  177. </span><span class="kwd">for</span><span class="pln"> </span><span class="pun">(</span><span class="typ">int16_t</span><span class="pln"> x</span><span class="pun">=</span><span class="lit">0</span><span class="pun">;</span><span class="pln"> x </span><span class="pun"><</span><span class="pln"> tft</span><span class="pun">.</span><span class="pln">width</span><span class="pun">();</span><span class="pln"> x</span><span class="pun">+=</span><span class="lit">6</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  178. tft</span><span class="pun">.</span><span class="pln">drawLine</span><span class="pun">(</span><span class="pln">tft</span><span class="pun">.</span><span class="pln">width</span><span class="pun">()-</span><span class="lit">1</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> x</span><span class="pun">,</span><span class="pln"> tft</span><span class="pun">.</span><span class="pln">height</span><span class="pun">()-</span><span class="lit">1</span><span class="pun">,</span><span class="pln"> color</span><span class="pun">);</span><span class="pln">
  179. delay</span><span class="pun">(</span><span class="lit">0</span><span class="pun">);</span><span class="pln">
  180. </span><span class="pun">}</span><span class="pln">
  181. </span><span class="kwd">for</span><span class="pln"> </span><span class="pun">(</span><span class="typ">int16_t</span><span class="pln"> y</span><span class="pun">=</span><span class="lit">0</span><span class="pun">;</span><span class="pln"> y </span><span class="pun"><</span><span class="pln"> tft</span><span class="pun">.</span><span class="pln">height</span><span class="pun">();</span><span class="pln"> y</span><span class="pun">+=</span><span class="lit">6</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  182. tft</span><span class="pun">.</span><span class="pln">drawLine</span><span class="pun">(</span><span class="pln">tft</span><span class="pun">.</span><span class="pln">width</span><span class="pun">()-</span><span class="lit">1</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> y</span><span class="pun">,</span><span class="pln"> color</span><span class="pun">);</span><span class="pln">
  183. delay</span><span class="pun">(</span><span class="lit">0</span><span class="pun">);</span><span class="pln">
  184. </span><span class="pun">}</span><span class="pln">
  185. tft</span><span class="pun">.</span><span class="pln">fillScreen</span><span class="pun">(</span><span class="pln">ST77XX_BLACK</span><span class="pun">);</span><span class="pln">
  186. </span><span class="kwd">for</span><span class="pln"> </span><span class="pun">(</span><span class="typ">int16_t</span><span class="pln"> x</span><span class="pun">=</span><span class="lit">0</span><span class="pun">;</span><span class="pln"> x </span><span class="pun"><</span><span class="pln"> tft</span><span class="pun">.</span><span class="pln">width</span><span class="pun">();</span><span class="pln"> x</span><span class="pun">+=</span><span class="lit">6</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  187. tft</span><span class="pun">.</span><span class="pln">drawLine</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> tft</span><span class="pun">.</span><span class="pln">height</span><span class="pun">()-</span><span class="lit">1</span><span class="pun">,</span><span class="pln"> x</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> color</span><span class="pun">);</span><span class="pln">
  188. delay</span><span class="pun">(</span><span class="lit">0</span><span class="pun">);</span><span class="pln">
  189. </span><span class="pun">}</span><span class="pln">
  190. </span><span class="kwd">for</span><span class="pln"> </span><span class="pun">(</span><span class="typ">int16_t</span><span class="pln"> y</span><span class="pun">=</span><span class="lit">0</span><span class="pun">;</span><span class="pln"> y </span><span class="pun"><</span><span class="pln"> tft</span><span class="pun">.</span><span class="pln">height</span><span class="pun">();</span><span class="pln"> y</span><span class="pun">+=</span><span class="lit">6</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  191. tft</span><span class="pun">.</span><span class="pln">drawLine</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> tft</span><span class="pun">.</span><span class="pln">height</span><span class="pun">()-</span><span class="lit">1</span><span class="pun">,</span><span class="pln"> tft</span><span class="pun">.</span><span class="pln">width</span><span class="pun">()-</span><span class="lit">1</span><span class="pun">,</span><span class="pln"> y</span><span class="pun">,</span><span class="pln"> color</span><span class="pun">);</span><span class="pln">
  192. delay</span><span class="pun">(</span><span class="lit">0</span><span class="pun">);</span><span class="pln">
  193. </span><span class="pun">}</span><span class="pln">
  194. tft</span><span class="pun">.</span><span class="pln">fillScreen</span><span class="pun">(</span><span class="pln">ST77XX_BLACK</span><span class="pun">);</span><span class="pln">
  195. </span><span class="kwd">for</span><span class="pln"> </span><span class="pun">(</span><span class="typ">int16_t</span><span class="pln"> x</span><span class="pun">=</span><span class="lit">0</span><span class="pun">;</span><span class="pln"> x </span><span class="pun"><</span><span class="pln"> tft</span><span class="pun">.</span><span class="pln">width</span><span class="pun">();</span><span class="pln"> x</span><span class="pun">+=</span><span class="lit">6</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  196. tft</span><span class="pun">.</span><span class="pln">drawLine</span><span class="pun">(</span><span class="pln">tft</span><span class="pun">.</span><span class="pln">width</span><span class="pun">()-</span><span class="lit">1</span><span class="pun">,</span><span class="pln"> tft</span><span class="pun">.</span><span class="pln">height</span><span class="pun">()-</span><span class="lit">1</span><span class="pun">,</span><span class="pln"> x</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> color</span><span class="pun">);</span><span class="pln">
  197. delay</span><span class="pun">(</span><span class="lit">0</span><span class="pun">);</span><span class="pln">
  198. </span><span class="pun">}</span><span class="pln">
  199. </span><span class="kwd">for</span><span class="pln"> </span><span class="pun">(</span><span class="typ">int16_t</span><span class="pln"> y</span><span class="pun">=</span><span class="lit">0</span><span class="pun">;</span><span class="pln"> y </span><span class="pun"><</span><span class="pln"> tft</span><span class="pun">.</span><span class="pln">height</span><span class="pun">();</span><span class="pln"> y</span><span class="pun">+=</span><span class="lit">6</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  200. tft</span><span class="pun">.</span><span class="pln">drawLine</span><span class="pun">(</span><span class="pln">tft</span><span class="pun">.</span><span class="pln">width</span><span class="pun">()-</span><span class="lit">1</span><span class="pun">,</span><span class="pln"> tft</span><span class="pun">.</span><span class="pln">height</span><span class="pun">()-</span><span class="lit">1</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> y</span><span class="pun">,</span><span class="pln"> color</span><span class="pun">);</span><span class="pln">
  201. delay</span><span class="pun">(</span><span class="lit">0</span><span class="pun">);</span><span class="pln">
  202. </span><span class="pun">}</span><span class="pln">
  203. </span><span class="pun">}</span><span class="pln">
  204. </span><span class="kwd">void</span><span class="pln"> testfastlines</span><span class="pun">(</span><span class="typ">uint16_t</span><span class="pln"> color1</span><span class="pun">,</span><span class="pln"> </span><span class="typ">uint16_t</span><span class="pln"> color2</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  205. tft</span><span class="pun">.</span><span class="pln">fillScreen</span><span class="pun">(</span><span class="pln">ST77XX_BLACK</span><span class="pun">);</span><span class="pln">
  206. </span><span class="kwd">for</span><span class="pln"> </span><span class="pun">(</span><span class="typ">int16_t</span><span class="pln"> y</span><span class="pun">=</span><span class="lit">0</span><span class="pun">;</span><span class="pln"> y </span><span class="pun"><</span><span class="pln"> tft</span><span class="pun">.</span><span class="pln">height</span><span class="pun">();</span><span class="pln"> y</span><span class="pun">+=</span><span class="lit">5</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  207. tft</span><span class="pun">.</span><span class="pln">drawFastHLine</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> y</span><span class="pun">,</span><span class="pln"> tft</span><span class="pun">.</span><span class="pln">width</span><span class="pun">(),</span><span class="pln"> color1</span><span class="pun">);</span><span class="pln">
  208. </span><span class="pun">}</span><span class="pln">
  209. </span><span class="kwd">for</span><span class="pln"> </span><span class="pun">(</span><span class="typ">int16_t</span><span class="pln"> x</span><span class="pun">=</span><span class="lit">0</span><span class="pun">;</span><span class="pln"> x </span><span class="pun"><</span><span class="pln"> tft</span><span class="pun">.</span><span class="pln">width</span><span class="pun">();</span><span class="pln"> x</span><span class="pun">+=</span><span class="lit">5</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  210. tft</span><span class="pun">.</span><span class="pln">drawFastVLine</span><span class="pun">(</span><span class="pln">x</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> tft</span><span class="pun">.</span><span class="pln">height</span><span class="pun">(),</span><span class="pln"> color2</span><span class="pun">);</span><span class="pln">
  211. </span><span class="pun">}</span><span class="pln">
  212. </span><span class="pun">}</span>
<span class="com">#include</span><span class="pln"> </span><span class="str"><Adafruit_GFX.h></span><span class="pln">    </span><span class="com">// Core graphics library</span><span class="pln">
</span><span class="com">#include</span><span class="pln"> </span><span class="str"><Adafruit_ST7735.h></span><span class="pln"> </span><span class="com">// Hardware-specific library for ST7735</span><span class="pln">
</span><span class="com">#include</span><span class="pln"> </span><span class="str"><Adafruit_ST7789.h></span><span class="pln"> </span><span class="com">// Hardware-specific library for ST7789</span><span class="pln">
</span><span class="com">#include</span><span class="pln"> </span><span class="str"><SPI.h></span><span class="pln">


</span><span class="com">#ifdef</span><span class="pln"> ADAFRUIT_HALLOWING
  </span><span class="com">#define</span><span class="pln"> TFT_CS        </span><span class="lit">39</span><span class="pln"> </span><span class="com">// Hallowing display control pins: chip select</span><span class="pln">
  </span><span class="com">#define</span><span class="pln"> TFT_RST       </span><span class="lit">37</span><span class="pln"> </span><span class="com">// Display reset</span><span class="pln">
  </span><span class="com">#define</span><span class="pln"> TFT_DC        </span><span class="lit">38</span><span class="pln"> </span><span class="com">// Display data/command select</span><span class="pln">
  </span><span class="com">#define</span><span class="pln"> TFT_BACKLIGHT  </span><span class="lit">7</span><span class="pln"> </span><span class="com">// Display backlight pin</span><span class="pln">
</span><span class="com">#else</span><span class="pln">
 
  </span><span class="com">#define</span><span class="pln"> TFT_CS        </span><span class="lit">10</span><span class="pln">
  </span><span class="com">#define</span><span class="pln"> TFT_RST        </span><span class="lit">9</span><span class="pln"> </span><span class="com">// Or set to -1 and connect to Arduino RESET pin</span><span class="pln">
  </span><span class="com">#define</span><span class="pln"> TFT_DC         </span><span class="lit">8</span><span class="pln">
</span><span class="com">#endif</span><span class="pln">

</span><span class="typ">Adafruit_ST7735</span><span class="pln"> tft </span><span class="pun">=</span><span class="pln"> </span><span class="typ">Adafruit_ST7735</span><span class="pun">(</span><span class="pln">TFT_CS</span><span class="pun">,</span><span class="pln"> TFT_DC</span><span class="pun">,</span><span class="pln"> TFT_RST</span><span class="pun">);</span><span class="pln">

</span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> CHARGE_PIN1 </span><span class="pun">=</span><span class="pln"> A1</span><span class="pun">;</span><span class="pln"> </span><span class="com">// display turns on when contact is made from the device to the dock</span><span class="pln">
</span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> CHARGE_PIN2 </span><span class="pun">=</span><span class="pln"> A2</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> CHARGE_TOLERANCE </span><span class="pun">=</span><span class="pln"> </span><span class="lit">20</span><span class="pun">;</span><span class="pln">


</span><span class="kwd">void</span><span class="pln"> setup</span><span class="pun">(</span><span class="kwd">void</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
</span><span class="com">#ifdef</span><span class="pln"> ADAFRUIT_HALLOWING
  tft</span><span class="pun">.</span><span class="pln">initR</span><span class="pun">(</span><span class="pln">INITR_HALLOWING</span><span class="pun">);</span><span class="pln">        </span><span class="com">// Initialize HalloWing-oriented screen</span><span class="pln">
  pinMode</span><span class="pun">(</span><span class="pln">TFT_BACKLIGHT</span><span class="pun">,</span><span class="pln"> OUTPUT</span><span class="pun">);</span><span class="pln">
  digitalWrite</span><span class="pun">(</span><span class="pln">TFT_BACKLIGHT</span><span class="pun">,</span><span class="pln"> HIGH</span><span class="pun">);</span><span class="pln"> </span><span class="com">// Backlight on</span><span class="pln">
</span><span class="com">#else</span><span class="pln">
  </span><span class="com">// Use this initializer if using a 1.8" TFT screen:</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">initR</span><span class="pun">(</span><span class="pln">INITR_BLACKTAB</span><span class="pun">);</span><span class="pln">      </span><span class="com">// Init ST7735S chip, black tab</span><span class="pln">
</span><span class="com">#endif</span><span class="pln">

  tft</span><span class="pun">.</span><span class="pln">setRotation</span><span class="pun">(</span><span class="lit">1</span><span class="pun">);</span><span class="pln"> </span><span class="com">// rotate the screen to horizontal </span><span class="pln">
  pinMode</span><span class="pun">(</span><span class="pln">CHARGE_PIN1</span><span class="pun">,</span><span class="pln"> INPUT</span><span class="pun">);</span><span class="pln"> 
  pinMode</span><span class="pun">(</span><span class="pln">CHARGE_PIN2</span><span class="pun">,</span><span class="pln"> INPUT</span><span class="pun">);</span><span class="pln">
  </span><span class="typ">Serial</span><span class="pun">.</span><span class="kwd">begin</span><span class="pun">(</span><span class="lit">9600</span><span class="pun">);</span><span class="pln">
  
  testfillcircles</span><span class="pun">(</span><span class="lit">10</span><span class="pun">,</span><span class="pln"> ST77XX_BLUE</span><span class="pun">);</span><span class="pln">
  testdrawcircles</span><span class="pun">(</span><span class="lit">10</span><span class="pun">,</span><span class="pln"> ST77XX_WHITE</span><span class="pun">);</span><span class="pln">
</span><span class="pun">}</span><span class="pln">

</span><span class="kwd">void</span><span class="pln"> loop</span><span class="pun">()</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  </span><span class="kwd">static</span><span class="pln"> </span><span class="kwd">bool</span><span class="pln"> plugged </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">;</span><span class="pln">
  </span><span class="kwd">int</span><span class="pln"> chargeRead1 </span><span class="pun">=</span><span class="pln"> analogRead</span><span class="pun">(</span><span class="pln">CHARGE_PIN1</span><span class="pun">);</span><span class="pln"> </span><span class="com">// reading if contact has been made </span><span class="pln">
  </span><span class="kwd">int</span><span class="pln"> chargeRead2 </span><span class="pun">=</span><span class="pln"> analogRead</span><span class="pun">(</span><span class="pln">CHARGE_PIN2</span><span class="pun">);</span><span class="pln">
</span><span class="com">//  Serial.println(chargeRead1);</span><span class="pln">
</span><span class="com">//  Serial.println(chargeRead2);</span><span class="pln">

  </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">((</span><span class="pln">chargeRead1 </span><span class="pun">-</span><span class="pln"> CHARGE_TOLERANCE </span><span class="pun"><=</span><span class="pln"> chargeRead2</span><span class="pun">)</span><span class="pln"> </span><span class="kwd">and</span><span class="pln">  </span><span class="com">// portable device not plugged in </span><span class="pln">
    </span><span class="pun">(</span><span class="pln">chargeRead2 </span><span class="pun"><=</span><span class="pln"> chargeRead1 </span><span class="pun">+</span><span class="pln"> CHARGE_TOLERANCE</span><span class="pun">))</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
      plugged </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">;</span><span class="pln">  
      tft</span><span class="pun">.</span><span class="pln">fillScreen</span><span class="pun">(</span><span class="pln">ST77XX_BLACK</span><span class="pun">);</span><span class="pln">
     </span><span class="pun">}</span><span class="pln">

  </span><span class="kwd">else</span><span class="pln"> </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">plugged </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="com">// this condition fires once we plug in </span><span class="pln">
    tftPrintTest</span><span class="pun">();</span><span class="pln">
    plugged </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">;</span><span class="pln"> </span><span class="com">// portable device marked as "plugged in" now</span><span class="pln">
</span><span class="pun">}</span><span class="pln">
  
  delay</span><span class="pun">(</span><span class="lit">500</span><span class="pun">);</span><span class="pln">
</span><span class="pun">}</span><span class="pln">


</span><span class="kwd">void</span><span class="pln"> tftPrintTest</span><span class="pun">()</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="com">// the content of the screens </span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">fillScreen</span><span class="pun">(</span><span class="pln">ST77XX_MAGENTA</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">setTextColor</span><span class="pun">(</span><span class="pln">ST77XX_WHITE</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">30</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">setTextSize</span><span class="pun">(</span><span class="lit">3</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"WELCOME"</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">60</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"HOME"</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">90</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"ELINOR!"</span><span class="pun">);</span><span class="pln">
  delay</span><span class="pun">(</span><span class="lit">3000</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">setTextSize</span><span class="pun">(</span><span class="lit">1</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">20</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">fillScreen</span><span class="pun">(</span><span class="pln">ST77XX_BLACK</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">setTextColor</span><span class="pun">(</span><span class="pln">ST77XX_WHITE</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"Hello Elinor!"</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">40</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"Hope you are having"</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">60</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"a great day."</span><span class="pun">);</span><span class="pln">
  delay</span><span class="pun">(</span><span class="lit">5000</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">fillScreen</span><span class="pun">(</span><span class="pln">ST77XX_BLUE</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">setTextColor</span><span class="pun">(</span><span class="pln">ST77XX_WHITE</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">10</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">setTextSize</span><span class="pun">(</span><span class="lit">2</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"Here are some"</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">30</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"breathing"</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">50</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"tips for you!"</span><span class="pun">);</span><span class="pln">
  delay</span><span class="pun">(</span><span class="lit">3000</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">fillScreen</span><span class="pun">(</span><span class="pln">ST77XX_BLUE</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">setTextColor</span><span class="pun">(</span><span class="pln">ST77XX_WHITE</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">10</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">setTextSize</span><span class="pun">(</span><span class="lit">2</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"First, take a"</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">30</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"long, slow"</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">55</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"INHALE."</span><span class="pun">);</span><span class="pln">
  delay</span><span class="pun">(</span><span class="lit">3000</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">fillScreen</span><span class="pun">(</span><span class="pln">ST77XX_BLUE</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">setTextColor</span><span class="pun">(</span><span class="pln">ST77XX_WHITE</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">10</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">setTextSize</span><span class="pun">(</span><span class="lit">2</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"Next, a quick"</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">30</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"and powerful"</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">55</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"EXHALE."</span><span class="pun">);</span><span class="pln">
  delay</span><span class="pun">(</span><span class="lit">3000</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">fillScreen</span><span class="pun">(</span><span class="pln">ST77XX_BLUE</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">setTextColor</span><span class="pun">(</span><span class="pln">ST77XX_WHITE</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">10</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"Take a total"</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">30</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"of 10 breaths"</span><span class="pun">);</span><span class="pln">
  delay</span><span class="pun">(</span><span class="lit">3000</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">fillScreen</span><span class="pun">(</span><span class="pln">ST77XX_WHITE</span><span class="pun">);</span><span class="pln">
  testfillcircles</span><span class="pun">(</span><span class="lit">10</span><span class="pun">,</span><span class="pln"> ST77XX_BLUE</span><span class="pun">);</span><span class="pln">
  testdrawcircles</span><span class="pun">(</span><span class="lit">10</span><span class="pun">,</span><span class="pln"> ST77XX_WHITE</span><span class="pun">);</span><span class="pln">
  delay</span><span class="pun">(</span><span class="lit">4000</span><span class="pun">);</span><span class="pln">
  testlines</span><span class="pun">(</span><span class="pln">ST77XX_YELLOW</span><span class="pun">);</span><span class="pln">
  delay</span><span class="pun">(</span><span class="lit">2000</span><span class="pun">);</span><span class="pln">
  testfastlines</span><span class="pun">(</span><span class="pln">ST77XX_RED</span><span class="pun">,</span><span class="pln"> ST77XX_BLUE</span><span class="pun">);</span><span class="pln">
  delay</span><span class="pun">(</span><span class="lit">2000</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">fillScreen</span><span class="pun">(</span><span class="pln">ST77XX_GREEN</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">setTextColor</span><span class="pun">(</span><span class="pln">ST77XX_WHITE</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">10</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">setTextSize</span><span class="pun">(</span><span class="lit">2</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"Here's a"</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">30</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"tip for you!"</span><span class="pun">);</span><span class="pln">
  delay</span><span class="pun">(</span><span class="lit">3000</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">fillScreen</span><span class="pun">(</span><span class="pln">ST77XX_GREEN</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">setTextColor</span><span class="pun">(</span><span class="pln">ST77XX_WHITE</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">10</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">setTextSize</span><span class="pun">(</span><span class="lit">2</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"Deep breaths"</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">30</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"increase your"</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">50</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"oxygen flow."</span><span class="pun">);</span><span class="pln">
  delay</span><span class="pun">(</span><span class="lit">2000</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">fillScreen</span><span class="pun">(</span><span class="pln">ST77XX_GREEN</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">setTextColor</span><span class="pun">(</span><span class="pln">ST77XX_WHITE</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">10</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">setTextSize</span><span class="pun">(</span><span class="lit">2</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"Also, it"</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">30</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"promotes a"</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">50</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"state of"</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">70</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"CALMNESS."</span><span class="pun">);</span><span class="pln">
  delay</span><span class="pun">(</span><span class="lit">5000</span><span class="pun">);</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">fillScreen</span><span class="pun">(</span><span class="pln">ST77XX_WHITE</span><span class="pun">);</span><span class="pln">
  testfillcircles</span><span class="pun">(</span><span class="lit">10</span><span class="pun">,</span><span class="pln"> ST77XX_BLUE</span><span class="pun">);</span><span class="pln">
  testdrawcircles</span><span class="pun">(</span><span class="lit">10</span><span class="pun">,</span><span class="pln"> ST77XX_WHITE</span><span class="pun">);</span><span class="pln">
</span><span class="pun">}</span><span class="pln">

</span><span class="kwd">void</span><span class="pln"> testfillcircles</span><span class="pun">(</span><span class="typ">uint8_t</span><span class="pln"> radius</span><span class="pun">,</span><span class="pln"> </span><span class="typ">uint16_t</span><span class="pln"> color</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="com">//graphics for elinor to view while breathing</span><span class="pln">
  </span><span class="kwd">for</span><span class="pln"> </span><span class="pun">(</span><span class="typ">int16_t</span><span class="pln"> x</span><span class="pun">=</span><span class="pln">radius</span><span class="pun">;</span><span class="pln"> x </span><span class="pun"><</span><span class="pln"> tft</span><span class="pun">.</span><span class="pln">width</span><span class="pun">();</span><span class="pln"> x</span><span class="pun">+=</span><span class="pln">radius</span><span class="pun">*</span><span class="lit">2</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
    </span><span class="kwd">for</span><span class="pln"> </span><span class="pun">(</span><span class="typ">int16_t</span><span class="pln"> y</span><span class="pun">=</span><span class="pln">radius</span><span class="pun">;</span><span class="pln"> y </span><span class="pun"><</span><span class="pln"> tft</span><span class="pun">.</span><span class="pln">height</span><span class="pun">();</span><span class="pln"> y</span><span class="pun">+=</span><span class="pln">radius</span><span class="pun">*</span><span class="lit">2</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
      tft</span><span class="pun">.</span><span class="pln">fillCircle</span><span class="pun">(</span><span class="pln">x</span><span class="pun">,</span><span class="pln"> y</span><span class="pun">,</span><span class="pln"> radius</span><span class="pun">,</span><span class="pln"> color</span><span class="pun">);</span><span class="pln">
    </span><span class="pun">}</span><span class="pln">
  </span><span class="pun">}</span><span class="pln">
</span><span class="pun">}</span><span class="pln">

</span><span class="kwd">void</span><span class="pln"> testdrawcircles</span><span class="pun">(</span><span class="typ">uint8_t</span><span class="pln"> radius</span><span class="pun">,</span><span class="pln"> </span><span class="typ">uint16_t</span><span class="pln"> color</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  </span><span class="kwd">for</span><span class="pln"> </span><span class="pun">(</span><span class="typ">int16_t</span><span class="pln"> x</span><span class="pun">=</span><span class="lit">0</span><span class="pun">;</span><span class="pln"> x </span><span class="pun"><</span><span class="pln"> tft</span><span class="pun">.</span><span class="pln">width</span><span class="pun">()+</span><span class="pln">radius</span><span class="pun">;</span><span class="pln"> x</span><span class="pun">+=</span><span class="pln">radius</span><span class="pun">*</span><span class="lit">2</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
    </span><span class="kwd">for</span><span class="pln"> </span><span class="pun">(</span><span class="typ">int16_t</span><span class="pln"> y</span><span class="pun">=</span><span class="lit">0</span><span class="pun">;</span><span class="pln"> y </span><span class="pun"><</span><span class="pln"> tft</span><span class="pun">.</span><span class="pln">height</span><span class="pun">()+</span><span class="pln">radius</span><span class="pun">;</span><span class="pln"> y</span><span class="pun">+=</span><span class="pln">radius</span><span class="pun">*</span><span class="lit">2</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
      tft</span><span class="pun">.</span><span class="pln">drawCircle</span><span class="pun">(</span><span class="pln">x</span><span class="pun">,</span><span class="pln"> y</span><span class="pun">,</span><span class="pln"> radius</span><span class="pun">,</span><span class="pln"> color</span><span class="pun">);</span><span class="pln">
    </span><span class="pun">}</span><span class="pln">
  </span><span class="pun">}</span><span class="pln">
</span><span class="pun">}</span><span class="pln">

</span><span class="kwd">void</span><span class="pln"> testlines</span><span class="pun">(</span><span class="typ">uint16_t</span><span class="pln"> color</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">fillScreen</span><span class="pun">(</span><span class="pln">ST77XX_BLACK</span><span class="pun">);</span><span class="pln">
  </span><span class="kwd">for</span><span class="pln"> </span><span class="pun">(</span><span class="typ">int16_t</span><span class="pln"> x</span><span class="pun">=</span><span class="lit">0</span><span class="pun">;</span><span class="pln"> x </span><span class="pun"><</span><span class="pln"> tft</span><span class="pun">.</span><span class="pln">width</span><span class="pun">();</span><span class="pln"> x</span><span class="pun">+=</span><span class="lit">6</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
    tft</span><span class="pun">.</span><span class="pln">drawLine</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> x</span><span class="pun">,</span><span class="pln"> tft</span><span class="pun">.</span><span class="pln">height</span><span class="pun">()-</span><span class="lit">1</span><span class="pun">,</span><span class="pln"> color</span><span class="pun">);</span><span class="pln">
    delay</span><span class="pun">(</span><span class="lit">0</span><span class="pun">);</span><span class="pln">
  </span><span class="pun">}</span><span class="pln">
  </span><span class="kwd">for</span><span class="pln"> </span><span class="pun">(</span><span class="typ">int16_t</span><span class="pln"> y</span><span class="pun">=</span><span class="lit">0</span><span class="pun">;</span><span class="pln"> y </span><span class="pun"><</span><span class="pln"> tft</span><span class="pun">.</span><span class="pln">height</span><span class="pun">();</span><span class="pln"> y</span><span class="pun">+=</span><span class="lit">6</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
    tft</span><span class="pun">.</span><span class="pln">drawLine</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> tft</span><span class="pun">.</span><span class="pln">width</span><span class="pun">()-</span><span class="lit">1</span><span class="pun">,</span><span class="pln"> y</span><span class="pun">,</span><span class="pln"> color</span><span class="pun">);</span><span class="pln">
    delay</span><span class="pun">(</span><span class="lit">0</span><span class="pun">);</span><span class="pln">
  </span><span class="pun">}</span><span class="pln">

  tft</span><span class="pun">.</span><span class="pln">fillScreen</span><span class="pun">(</span><span class="pln">ST77XX_BLACK</span><span class="pun">);</span><span class="pln">
  </span><span class="kwd">for</span><span class="pln"> </span><span class="pun">(</span><span class="typ">int16_t</span><span class="pln"> x</span><span class="pun">=</span><span class="lit">0</span><span class="pun">;</span><span class="pln"> x </span><span class="pun"><</span><span class="pln"> tft</span><span class="pun">.</span><span class="pln">width</span><span class="pun">();</span><span class="pln"> x</span><span class="pun">+=</span><span class="lit">6</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
    tft</span><span class="pun">.</span><span class="pln">drawLine</span><span class="pun">(</span><span class="pln">tft</span><span class="pun">.</span><span class="pln">width</span><span class="pun">()-</span><span class="lit">1</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> x</span><span class="pun">,</span><span class="pln"> tft</span><span class="pun">.</span><span class="pln">height</span><span class="pun">()-</span><span class="lit">1</span><span class="pun">,</span><span class="pln"> color</span><span class="pun">);</span><span class="pln">
    delay</span><span class="pun">(</span><span class="lit">0</span><span class="pun">);</span><span class="pln">
  </span><span class="pun">}</span><span class="pln">
  </span><span class="kwd">for</span><span class="pln"> </span><span class="pun">(</span><span class="typ">int16_t</span><span class="pln"> y</span><span class="pun">=</span><span class="lit">0</span><span class="pun">;</span><span class="pln"> y </span><span class="pun"><</span><span class="pln"> tft</span><span class="pun">.</span><span class="pln">height</span><span class="pun">();</span><span class="pln"> y</span><span class="pun">+=</span><span class="lit">6</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
    tft</span><span class="pun">.</span><span class="pln">drawLine</span><span class="pun">(</span><span class="pln">tft</span><span class="pun">.</span><span class="pln">width</span><span class="pun">()-</span><span class="lit">1</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> y</span><span class="pun">,</span><span class="pln"> color</span><span class="pun">);</span><span class="pln">
    delay</span><span class="pun">(</span><span class="lit">0</span><span class="pun">);</span><span class="pln">
  </span><span class="pun">}</span><span class="pln">

  tft</span><span class="pun">.</span><span class="pln">fillScreen</span><span class="pun">(</span><span class="pln">ST77XX_BLACK</span><span class="pun">);</span><span class="pln">
  </span><span class="kwd">for</span><span class="pln"> </span><span class="pun">(</span><span class="typ">int16_t</span><span class="pln"> x</span><span class="pun">=</span><span class="lit">0</span><span class="pun">;</span><span class="pln"> x </span><span class="pun"><</span><span class="pln"> tft</span><span class="pun">.</span><span class="pln">width</span><span class="pun">();</span><span class="pln"> x</span><span class="pun">+=</span><span class="lit">6</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
    tft</span><span class="pun">.</span><span class="pln">drawLine</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> tft</span><span class="pun">.</span><span class="pln">height</span><span class="pun">()-</span><span class="lit">1</span><span class="pun">,</span><span class="pln"> x</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> color</span><span class="pun">);</span><span class="pln">
    delay</span><span class="pun">(</span><span class="lit">0</span><span class="pun">);</span><span class="pln">
  </span><span class="pun">}</span><span class="pln">
  </span><span class="kwd">for</span><span class="pln"> </span><span class="pun">(</span><span class="typ">int16_t</span><span class="pln"> y</span><span class="pun">=</span><span class="lit">0</span><span class="pun">;</span><span class="pln"> y </span><span class="pun"><</span><span class="pln"> tft</span><span class="pun">.</span><span class="pln">height</span><span class="pun">();</span><span class="pln"> y</span><span class="pun">+=</span><span class="lit">6</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
    tft</span><span class="pun">.</span><span class="pln">drawLine</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> tft</span><span class="pun">.</span><span class="pln">height</span><span class="pun">()-</span><span class="lit">1</span><span class="pun">,</span><span class="pln"> tft</span><span class="pun">.</span><span class="pln">width</span><span class="pun">()-</span><span class="lit">1</span><span class="pun">,</span><span class="pln"> y</span><span class="pun">,</span><span class="pln"> color</span><span class="pun">);</span><span class="pln">
    delay</span><span class="pun">(</span><span class="lit">0</span><span class="pun">);</span><span class="pln">
  </span><span class="pun">}</span><span class="pln">

  tft</span><span class="pun">.</span><span class="pln">fillScreen</span><span class="pun">(</span><span class="pln">ST77XX_BLACK</span><span class="pun">);</span><span class="pln">
  </span><span class="kwd">for</span><span class="pln"> </span><span class="pun">(</span><span class="typ">int16_t</span><span class="pln"> x</span><span class="pun">=</span><span class="lit">0</span><span class="pun">;</span><span class="pln"> x </span><span class="pun"><</span><span class="pln"> tft</span><span class="pun">.</span><span class="pln">width</span><span class="pun">();</span><span class="pln"> x</span><span class="pun">+=</span><span class="lit">6</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
    tft</span><span class="pun">.</span><span class="pln">drawLine</span><span class="pun">(</span><span class="pln">tft</span><span class="pun">.</span><span class="pln">width</span><span class="pun">()-</span><span class="lit">1</span><span class="pun">,</span><span class="pln"> tft</span><span class="pun">.</span><span class="pln">height</span><span class="pun">()-</span><span class="lit">1</span><span class="pun">,</span><span class="pln"> x</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> color</span><span class="pun">);</span><span class="pln">
    delay</span><span class="pun">(</span><span class="lit">0</span><span class="pun">);</span><span class="pln">
  </span><span class="pun">}</span><span class="pln">
  </span><span class="kwd">for</span><span class="pln"> </span><span class="pun">(</span><span class="typ">int16_t</span><span class="pln"> y</span><span class="pun">=</span><span class="lit">0</span><span class="pun">;</span><span class="pln"> y </span><span class="pun"><</span><span class="pln"> tft</span><span class="pun">.</span><span class="pln">height</span><span class="pun">();</span><span class="pln"> y</span><span class="pun">+=</span><span class="lit">6</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
    tft</span><span class="pun">.</span><span class="pln">drawLine</span><span class="pun">(</span><span class="pln">tft</span><span class="pun">.</span><span class="pln">width</span><span class="pun">()-</span><span class="lit">1</span><span class="pun">,</span><span class="pln"> tft</span><span class="pun">.</span><span class="pln">height</span><span class="pun">()-</span><span class="lit">1</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> y</span><span class="pun">,</span><span class="pln"> color</span><span class="pun">);</span><span class="pln">
    delay</span><span class="pun">(</span><span class="lit">0</span><span class="pun">);</span><span class="pln">
  </span><span class="pun">}</span><span class="pln">
</span><span class="pun">}</span><span class="pln">

</span><span class="kwd">void</span><span class="pln"> testfastlines</span><span class="pun">(</span><span class="typ">uint16_t</span><span class="pln"> color1</span><span class="pun">,</span><span class="pln"> </span><span class="typ">uint16_t</span><span class="pln"> color2</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  tft</span><span class="pun">.</span><span class="pln">fillScreen</span><span class="pun">(</span><span class="pln">ST77XX_BLACK</span><span class="pun">);</span><span class="pln">
    </span><span class="kwd">for</span><span class="pln"> </span><span class="pun">(</span><span class="typ">int16_t</span><span class="pln"> y</span><span class="pun">=</span><span class="lit">0</span><span class="pun">;</span><span class="pln"> y </span><span class="pun"><</span><span class="pln"> tft</span><span class="pun">.</span><span class="pln">height</span><span class="pun">();</span><span class="pln"> y</span><span class="pun">+=</span><span class="lit">5</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
      tft</span><span class="pun">.</span><span class="pln">drawFastHLine</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> y</span><span class="pun">,</span><span class="pln"> tft</span><span class="pun">.</span><span class="pln">width</span><span class="pun">(),</span><span class="pln"> color1</span><span class="pun">);</span><span class="pln">
      </span><span class="pun">}</span><span class="pln">
    </span><span class="kwd">for</span><span class="pln"> </span><span class="pun">(</span><span class="typ">int16_t</span><span class="pln"> x</span><span class="pun">=</span><span class="lit">0</span><span class="pun">;</span><span class="pln"> x </span><span class="pun"><</span><span class="pln"> tft</span><span class="pun">.</span><span class="pln">width</span><span class="pun">();</span><span class="pln"> x</span><span class="pun">+=</span><span class="lit">5</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
      tft</span><span class="pun">.</span><span class="pln">drawFastVLine</span><span class="pun">(</span><span class="pln">x</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> tft</span><span class="pun">.</span><span class="pln">height</span><span class="pun">(),</span><span class="pln"> color2</span><span class="pun">);</span><span class="pln">
      </span><span class="pun">}</span><span class="pln">
</span><span class="pun">}</span>

3D fabrication files:

Link to A360