# Example: Logging and graphing data from your Spark Core using Google

**URL:** <https://community.particle.io/t/example-logging-and-graphing-data-from-your-spark-core-using-google/2929>\
**Category:** Project Share\
**Created:** [February 17, 2014, 8:31pm UTC](https://community.particle.io/t/example-logging-and-graphing-data-from-your-spark-core-using-google/2929 "2014-02-17T20:31:19Z")\
**Posts on this page:** 1\
**Showing post:** 177

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [December 11, 2015, 7:22am UTC](https://community.particle.io/t/example-logging-and-graphing-data-from-your-spark-core-using-google/2929/177 "2015-12-11T07:22:47Z")

</div>

> [@brybrew](#):
>
> So change declaration of int count = 0; to volatile int count = 0; ?

Yes.

> [@brybrew](#):
>
> Who is this "code optimizer" and why would he get in my way?

This is a part of the compiler that looks at your code and tries to improve it for speed or/and size.  
And hence it might happen when it looks at a part of your code where you use `count` multiple times it will optimize this part in a way where it only retrieves it once from memory and uses it over and over again, ignoring any change made by the interrupt. `volatile` tells it to _ **always** _ retrieve the current value from mem.

Your blink will be unobservably fast the way you do it there.  
If you do this, you'll get a LED toggle with each bubble

```cpp
void bubbleCounting (void) {
    count++;
    digitalWriteFast(Led2, !pinReadFast(Led2)); // toggle led
}

```

> [@brybrew](#):
>
> Seems like they take priority over whatever is taking place in the loop, correct? What if my code is in the loop and trying to connect to server to upload ...

Correct, hence the need to keep them short and fast so the upload won't even notice.  
So also no need to mask the interrupts since it will return and carry on just where it left off before the interrupt.  
But in order to avoid missing a count, you might want to do `count = 0;` **immediately after** this line ` request.body = "{\"value\":" + String(count) + "}";`

---

_[View the full topic](https://community.particle.io/t/example-logging-and-graphing-data-from-your-spark-core-using-google/2929)._
