Skip to content

Instantly share code, notes, and snippets.

@anchan828
Created May 10, 2013 05:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anchan828/5552597 to your computer and use it in GitHub Desktop.
Save anchan828/5552597 to your computer and use it in GitHub Desktop.
UniduinoでServoを動かすサンプル
using UnityEngine;
using System.Collections;
using Uniduino;
public class Sample : MonoBehaviour
{
private Arduino arduino;
private int angle;
void Start ()
{
arduino = Arduino.global;
arduino.Setup (() => arduino.pinMode (9, PinMode.SERVO));
StartCoroutine (BlinkLoop ());
}
IEnumerator BlinkLoop ()
{
while (true) {
arduino.analogWrite (9, angle);
yield return new WaitForEndOfFrame();
}
}
void OnGUI ()
{
GUILayout.Label (string.Format ("Angle {0}", angle));
angle = (int)GUILayout.HorizontalSlider (angle, 0, 179, GUILayout.Width (300));
}
}
@anchan828
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment