Search Unity

Anybody mess with Arduino or anything, to help with learn programming or relax?

Discussion in 'General Discussion' started by BlankDeedxxAldenHilcrest, Nov 29, 2018.

  1. BlankDeedxxAldenHilcrest

    BlankDeedxxAldenHilcrest

    Joined:
    Jul 10, 2018
    Posts:
    292
    I was going crazy from working on my game and had to force take a mental vacation for the health of me and my company. I got into soldering small electrical devices together, simple devices and whatnot. Then I started looking at Arduino, thinking it might be just as fun as soldering, but also be a sneaky way to teach me comprehensive C++. Anybody learn any coding from Arduino tinkering, or have any thoughts?
     
  2. Billy4184

    Billy4184

    Joined:
    Jul 7, 2014
    Posts:
    6,025
    It's a lot of fun, and I'm building a solar/battery monitoring system with it for my boat. Other than the mental vacation though, it hasn't contributed a whole lot to game dev.
     
    dogzerx2 likes this.
  3. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    My side project right now is home automation. I use Z-Wave. Its really fun. My controller uses LUA as script language.
     
    dogzerx2 likes this.
  4. Vanamerax

    Vanamerax

    Joined:
    Jan 12, 2012
    Posts:
    938
    I have done some stuff with arduino's controlling WS2812 LED strips. These can be controlled per-pixel and can create some interesting effects. Have done a room-lighting project for someone's hobby room using this stuff.

    Would recommend using Visual Studio Code with Platform IO if your project gets any larger than a hundred lines of code or so.
     
    dogzerx2 likes this.
  5. Kjelle69

    Kjelle69

    Joined:
    Nov 9, 2016
    Posts:
    53
    I am working on a serial communication routine that can control Unity through sensors from an Arduino.
    Really interesting :)



    Arduino Code:

    void setup() {



    pinMode(12, INPUT_PULLUP);

    pinMode(13, OUTPUT);

    pinMode(LED_BUILTIN, OUTPUT);

    Serial.begin(9600);

    }



    void loop() {

    int SW1 = digitalRead(12);

    if (SW1 == LOW)

    {

    digitalWrite(13, HIGH);

    Serial.write(1);

    delay(20);

    }

    else

    {

    digitalWrite(13, LOW);

    Serial.write(2);

    delay(20);

    }

    }



    Unity Code:

    using UnityEngine;
    using System.IO.Ports;



    public class Input : MonoBehaviour
    {
    public float speed;
    public float amountToMove;

    SerialPort sp = new SerialPort("COM3",9600);

    // Use this for initialization
    void Start ()
    {
    sp.Open();
    sp.ReadTimeout = 1;
    }

    // Update is called once per frame
    void Update ()
    {
    amountToMove = speed * Time.deltaTime;

    if(sp.IsOpen)
    {
    try
    {
    MoveObject(sp.ReadByte());
    }
    catch (System.Exception)
    {

    }
    }

    }

    void MoveObject(int Pedal)
    {
    if (Pedal == 1)
    {
    transform.Translate(Vector3.up * amountToMove, Space.World);
    }
    if (Pedal == 2)
    {
    transform.Translate(Vector3.down * amountToMove, Space.World);
    }
    }
    }

     
  6. dogzerx2

    dogzerx2

    Joined:
    Dec 27, 2009
    Posts:
    3,971
    I haven't ever messed with arduino at all but it's in my bucket list. Very interesting thread!
     
  7. BlankDeedxxAldenHilcrest

    BlankDeedxxAldenHilcrest

    Joined:
    Jul 10, 2018
    Posts:
    292
    I think this is really cool.
     
    Kjelle69 and dogzerx2 like this.
  8. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    Here is my current project btw (Z-Wave)

     
    dogzerx2 likes this.
  9. Voronoi

    Voronoi

    Joined:
    Jul 2, 2012
    Posts:
    590
    I've used Arduino's for getting input into Unity and it's pretty fun. Here's a capacitive touch sensor that I made: https://github.com/bryanrtboy/ArduinoSerialThreading


    The curve represents the 'kind' of touch, rather than just on or off. This project forced me to learn more about threaded operations, which is really a must when using Arduino's for inputs to a PC.

    In terms of fun, and learning programming I had a lot of fun working recently with Raspberry Pi's and openframeworks. What's nice about OF is you can develop on a mac or PC, and then easily port to the PI. I learned a lot about the different video formats required for a low end device like the PI. And, the PI has GPIO pins that can make it act like an Arduino and use sensors.
     
  10. RichardKain

    RichardKain

    Joined:
    Oct 1, 2012
    Posts:
    1,261
    I learned how to program in Python so that I'd finally be able to code for my Raspberry Pi. I'm glad I did, there's a lot more fun stuff that I can do with my Pi now. Also, Python is very easy for even a partially experienced programmer to pick up, it only took about a week and a half of practice for me to familiarize myself with the syntax. I'm planning on cooking up a rudimentary point-and-click framework using Tilengine that I will be able to run on my Raspberry Pi, as well as port to Unity.
     
    Kjelle69 likes this.