using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Uduino;

public class MPR121 : MonoBehaviour
{

    public Image[] images;

    void Start()
    {
        UduinoManager.Instance.OnDataReceived += DataReceived;
    }

    void Update()
    {
      
    }

    void DataReceived(string data, UduinoDevice baord)
    {
        string[] values = data.Split(' ');
        int pressed = 0;
        bool ok = int.TryParse(values[0], out pressed); // Trying to parse data to a float
        string status = values[1];

        if (ok)
        {
            Debug.Log("Finding new touch " + data);
            if (status == "touched") images[pressed].color = new Color(0, 1, 1);
            else if (status == "released") images[pressed].color = new Color(0, 0, 0);
        }
        else
        {
            Debug.Log("Error parsing " + data);
        }
    }
}
