# How to save last selections on Processing

**URL:** <https://discourse.processing.org/t/how-to-save-last-selections-on-processing/21695>\
**Category:** Electronics (Arduino, etc.)\
**Created:** [June 9, 2020, 3:52am UTC](https://discourse.processing.org/t/how-to-save-last-selections-on-processing/21695 "2020-06-09T03:52:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jensenphan](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@jensenphan](https://discourse.processing.org/u/jensenphan)\
**Post date:** [June 9, 2020, 3:52am UTC](https://discourse.processing.org/t/how-to-save-last-selections-on-processing/21695/1 "2020-06-09T03:52:02Z")

</div>

Hi everyone, i am an amatur coder.  
I want to use Processing as user interface to controll my arduino with LED color.  
I want to save config i choose on Processing. My mean the User interface will show last select when i open UI again.  
Please help me. So sorry, i dont know what’s keyword to search this case so i create the topic.

---

<div class="post-metadata">

**Author:** ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)\
**Post date:** [June 9, 2020, 9:09am UTC](https://discourse.processing.org/t/how-to-save-last-selections-on-processing/21695/2 "2020-06-09T09:09:25Z")

</div>

Hi,

Welcome to the community! 🙂

If you want to save information from one run to another, you need to store it on your computer in a file format. You can either create your own and then read it after and change your UI accordingly or use a predefined file format.

Are you using a specific GUI library like G4P or ControlP5?

You might be interested in saving in JSON or XML :

- [https://processing.org/reference/XML.html](https://processing.org/reference/XML.html)
- [https://processing.org/reference/JSONObject.html](https://processing.org/reference/JSONObject.html)

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [June 9, 2020, 7:25pm UTC](https://discourse.processing.org/t/how-to-save-last-selections-on-processing/21695/3 "2020-06-09T19:25:01Z")

</div>

Here is an example

- It simulates a GUI of buttons stored in `list0`
- You can alter each of the 3 buttons with keys 1,2,3
- When you leave, current settings is stored
- when you load, either there is a file then its content is restored OR there is no file (first time) then nothing is loaded

Chrisir

```auto

// classButton 
ArrayList<ClassButton> list0=new ArrayList();
String[] arrString; 

void setup() {
  size(800, 800);
  background(0);

  list0.add(new ClassButton()); 
  list0.add(new ClassButton()); 
  list0.add(new ClassButton());  

  // load
  arrString=loadStrings("data.txt");
  // successful?
  if (arrString!=null) {
    // Yes, load 
    int i=0; 
    for (ClassButton pv : list0) {
      pv.value = int( arrString[i] );
      i++;
    }
  }//if
}

void draw() {
  background(0);

  // show entire list
  noStroke(); 
  for (ClassButton pv : list0) {
    pv.display();
  }//for
}//draw()

// -----------------------------------------------------------------------
// Inputs

void keyPressed() {
  switch (key) {
  case '1':
    list0.get(0).inc(); 
    break; 
  case '2':
    list0.get(1).inc();
    break; 
  case '3':
    list0.get(2).inc();
    break;

  case ESC:
    exitMy() ;
    break;
  }//case
}

void exitMy() {
  //println ("leave");
  String[] arrS = new String[3];
  arrS[0] = new String( list0.get(0).value+"");
  arrS[1] = new String( list0.get(1).value+""); 
  arrS[2] = new String( list0.get(2).value+""); 
  // printArray (arrS);
  saveStrings("data.txt", arrS);
}

//================================================================================

class ClassButton {

  int value; 
  float x = list0.size() * 45 + 34; 

  void inc() {
    value++;
    if (value>2)
      value=0;
  }//method

  void display() {
    text(value, 
      x, 45);
  }//method
}//class
//

```

---

<div class="post-metadata">

**Author:** ![jensenphan](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@jensenphan](https://discourse.processing.org/u/jensenphan)\
**Post date:** [June 16, 2020, 6:08am UTC](https://discourse.processing.org/t/how-to-save-last-selections-on-processing/21695/4 "2020-06-16T06:08:36Z")

</div>

Thank you so much. i will try it
