Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using System.IO.Ports;
- public class ColourModifier : MonoBehaviour
- {
- public float red;
- public float green;
- public float blue;
- public int LightEffect;
- public int LightMode;
- public float Speed;
- public float Brightness;
- private int input;
- public float redAnimation;
- public float greenAnimation;
- public float blueAnimation;
- public int TriNumber = 1;
- public int PlayDesign;
- //Switching (Scenes)
- public GameObject Design;
- public GameObject Gallery;
- public GameObject PreMadeEffects;
- public GameObject DesignOptionsTab;
- public Image[] TriangePreviews;
- //Animations
- public GameObject PreMadeEffectsOptions;
- public int OnOrOff;
- public static SerialPort sp = new SerialPort("COM7", 9600);
- public void Start()
- {
- OpenConnection();
- PreMadeEffects.SetActive(true);
- Gallery.SetActive(false);
- Design.SetActive(false);
- DesignOptionsTab.SetActive(false);
- PreMadeEffectsOptions.SetActive(false);
- }
- public void Update()
- {
- }
- public void Increment()
- {
- TriNumber++;
- if (TriNumber == 10)
- {
- TriNumber = 1;
- }
- }
- public void Decrease()
- {
- TriNumber--;
- if (TriNumber == 0)
- {
- TriNumber = 9;
- }
- }
- //Effects
- public void Effect(int Effect)
- {
- LightEffect = Effect;
- PreMadeEffectsOptions.SetActive(true);
- Debug.Log(LightEffect);
- }
- public void Mode(int Mode)
- {
- LightMode = Mode;
- }
- public void PlayPreMadeEffect()
- {
- sp.Write("1" + LightEffect.ToString());
- Debug.Log("Sent To Arduino: " + "1" + LightEffect.ToString());
- }
- public void Red(float RedValue)
- {
- red = RedValue;
- }
- public void Green(float GreenValue)
- {
- green = GreenValue;
- }
- public void Blue(float BlueValue)
- {
- blue = BlueValue;
- //TriangePreviews[TriNumber] = new Color32((byte)red, (byte)green, (byte)blue, 255);
- }
- public void SwitchToDesign()
- {
- PreMadeEffects.SetActive(false);
- Gallery.SetActive(false);
- Design.SetActive(true);
- DesignOptionsTab.SetActive(false);
- PreMadeEffectsOptions.SetActive(false);
- }
- public void OnOrOffButton()
- {
- if(OnOrOff == 0)
- {
- sp.Write("01");
- }
- if (OnOrOff == 1)
- {
- sp.Write("02");
- }
- OnOrOff++;
- if(OnOrOff == 2)
- {
- OnOrOff == 0;
- }
- }
- public void OpenConnection()
- {
- if (sp != null)
- {
- if (sp.IsOpen)
- {
- sp.Close();
- Debug.Log("Closing, As It Was Already Open");
- }
- else
- {
- sp.Open();
- Debug.Log("Port Has Been Opened");
- }
- }
- else
- {
- if (sp.IsOpen)
- {
- Debug.Log("Port Is Already Open");
- }
- else
- {
- Debug.Log("Port == null");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement