# Storing all incoming data and button not working

**URL:** <https://discourse.processing.org/t/storing-all-incoming-data-and-button-not-working/26398>\
**Category:** Electronics (Arduino, etc.)\
**Created:** [December 20, 2020, 12:15pm UTC](https://discourse.processing.org/t/storing-all-incoming-data-and-button-not-working/26398 "2020-12-20T12:15:36Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [December 29, 2020, 11:56pm UTC](https://discourse.processing.org/t/storing-all-incoming-data-and-button-not-working/26398/4 "2020-12-29T23:56:17Z")

</div>

Hello,

Here is the simplest example of collecting data into an ArrayList of Integers.

> **Example Code**
>
> ```auto
> //This program takes ASCII-encoded strings
> 
> //from the serial port at 9600 baud and graphs them. It expects values in the
> //range 0 to 1023, followed by a newline, or newline and carriage return
> 
> IntList data;
> 
> import processing.serial.*;
> 
> Serial myPort; // The serial port - object from serial class
> //String[] list = new String[3]; // For serial port
> 
> int inData;
> 
> boolean newData = false;
> boolean record = false;
> boolean dataReady = false;
> 
> int counter;
> 
> void setup () 
> {
> size(200, 400); // Set the window size:   
> background(0);
> 
> data = new IntList();
>   
> // List all the available serial ports
> printArray(Serial.list());
>   
> String portName = Serial.list()[2];
> myPort = new Serial(this, portName, 9600); // A serialEvent() is generated when a newline character is received
> myPort.bufferUntil('\n'); // Sets a specific byte to buffer until before calling serialEvent()
> delay(1000);
>  
> textSize(16);
> //noLoop();
> }
> 
> void draw () 
> {
> //background(0);
> if(dataReady)
> {
> println(data);
> for(int i=0; i<16; i++)
> {
> text(data.get(i), 10, i*20+20);
> }
> dataReady = false;
> data.clear();
> }
> }
> 
> void serialEvent (Serial myPort) 
> {
> // get the ASCII string:
> String inString = myPort.readStringUntil('\n');
> //println(inString);
> if (inString != null) 
> {
> inString = trim(inString); // trim off whitespaces.
>     
> //inByte = float(inString); // convert to a number
> //inByte = map(inByte, 0, 1023, 0, height); // map to the screen height.
> //newData = true; 
>     
> if (record)
> {
> data.append(int(inString));
> println(counter++);
> if (data.size() >= 16)
> {
> record = false;
> dataReady = true;
> println("Data ready!");
> counter = 0;
> }
> }
> }
> }
> 
> void mousePressed()
> {
> record = true;
> background(0);
> }
> 
> ```

The incoming data is a string (integer); I converted the string to an integer.  
mousePressed() will store 16 integer values and display to screen.

You can easily adapt these concepts with a timer and store data.

There are plenty of examples of timers in this forum.

`:)`

---

_[View the full topic](https://discourse.processing.org/t/storing-all-incoming-data-and-button-not-working/26398)._
