Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by KnightRiderGuy · Nov 28, 2015 at 01:25 PM · c#uiupdatecodepagearduino

Need Help With Arduino Code to Unity

I'm having some issues understanding what I need to do in order to make my Arduino code send information to Unity for me to be able to change the Unity UI based on the status of an Arduino pin or LED on or off status.

I'm also wondering why on start up pin 13 flashes? Is there a way to disable that on start up flashing as any device I have hooked up to it will flash when activated. And well lol If I have K.I.T.T.s Oil Slick function connected to that pin then every time I start the system he'll spooge oil all over the garage floor, and well... we can't have that now can we ;) lol

Here is my Arduino code that I am working with.

 int lightPin = 0; //Define Pin For Photoresistor
 int lightInt = 0;
 //int lightLevel = analogRead(0);
 //int threshold = 250;
 //int range = 50;
 
 const byte rLed = 12; //Sets Pin number LED is conneted too
 const byte rLed2 = 1;
 const byte yLed = 11;
 const byte gLed = 10;
 const byte gLed2 = 5;
 const byte gLed3 = 4;
 const byte wLed = 3;
 const byte bLed = 2;
 const byte bLed2 = 13;
 char myChar;         //changed the name of this variable because they are not all colurs now
 const byte pulsePins[] = {6, 7, 8, 9};  //pins for a pulse output
 char pulseTriggers[] = {'p', 'q','R','L'};
 const int NUMBER_OF_PULSE_PINS = sizeof(pulsePins);
 unsigned long pulseStarts[NUMBER_OF_PULSE_PINS];
 unsigned long pulseLength = 500;
 
 void setup()
 {
   //Serial.begin (9600);
   Serial.begin (115200);
   Serial.setTimeout(13); //Added today Sun Nov 22 ( not sure if this is needed? )
   pinMode(wLed, OUTPUT);
   pinMode(rLed, OUTPUT);
   pinMode(rLed2, OUTPUT);
   pinMode(yLed, OUTPUT);
   pinMode(gLed, OUTPUT);
   pinMode(gLed2, OUTPUT);
   pinMode(gLed3, OUTPUT);
   pinMode(bLed, OUTPUT);
   pinMode(bLed2, OUTPUT);
   digitalWrite(wLed, LOW);
   digitalWrite(rLed, LOW);
   digitalWrite(rLed2, LOW);
   digitalWrite(yLed, LOW);
   digitalWrite(gLed, LOW);
   digitalWrite(gLed2, LOW);
   digitalWrite(gLed3, LOW);
   digitalWrite(bLed, LOW);
   digitalWrite(bLed2, LOW);
   
   for (int p = 0; p < NUMBER_OF_PULSE_PINS; p++)
   {
     pinMode(pulsePins[p], OUTPUT);
     digitalWrite(pulsePins[p], LOW);
   }
 }
 
 void loop()
 { 
   //Light Sensor
     if((lightInt - analogRead(lightPin)) > 500 || (lightInt - analogRead(lightPin)) < -500){
       lightInt = analogRead(lightPin);
       Serial.println(lightInt);
     }
     //read the current light level.
     /*int lightLevel = analogRead(lightPin);
     //If the light level is within our desired range, send it to Unity.
     if(lightLevel > threshold - range && lightLevel < threshold + range)
     Serial.println(lightLevel);
     */
   if (Serial.available())              //if serial data is available
   {
     
     int lf = 10;
 
     myChar = Serial.read();             //read one character from serial
     if (myChar == 'r')                  //if it is an r
     {
       digitalWrite(rLed, !digitalRead(rLed));  //Oil Slick Toggle
     }
     if (myChar == 'b')
     {
       digitalWrite(bLed, !digitalRead(bLed)); //Surveillance Mode Toggle
     }
 
     if (myChar == 'y')
     {
       digitalWrite(yLed, !digitalRead(yLed)); //Movie Player Toggle
     }
 
     if (myChar == 'g')
     {
       digitalWrite(gLed, !digitalRead(gLed)); //Auto Phone Toggle
     }
 
     if (myChar == '1')
     {
       digitalWrite(bLed2, !digitalRead(bLed2)); //Scanner Toggle
     }
 
     if (myChar == 'f')
     {
       digitalWrite(gLed2, !digitalRead(gLed2)); //Fog Lights Toggle
     }
 
     if (myChar == 'h')
     {
       digitalWrite(gLed3, !digitalRead(gLed3)); //Head Lights Toggle
     }
 
     if (myChar == 'H')
     {
       digitalWrite(wLed, !digitalRead(wLed)); //High Beams Toggle
     }
 
 
     //Rear Hatch Popper
     for (int p = 0; p < NUMBER_OF_PULSE_PINS; p++)
     {
       if (myChar == pulseTriggers[p])
       {
         pulseStarts[p] = millis();  //save the time of receipt
         digitalWrite(pulsePins[p], HIGH);
       }
     }
 
 
     //Grappling Hook Launch
     for (int q = 0; q < NUMBER_OF_PULSE_PINS; q++)
     {
       if (myChar == pulseTriggers[q])
       {
         pulseStarts[q] = millis();  //save the time of receipt
         digitalWrite(pulsePins[q], HIGH);
       }
     }
 
 
     //Auto Doors Right Pulse
     for (int R = 0; R < NUMBER_OF_PULSE_PINS; R++)
     {
       if (myChar == pulseTriggers[R])
       {
         pulseStarts[R] = millis();  //save the time of receipt
         digitalWrite(pulsePins[R], HIGH);
       }
     }
 
 
     //Auto Doors Left Pulse
     for (int L = 0; L < NUMBER_OF_PULSE_PINS; L++)
     {
       if (myChar == pulseTriggers[L])
       {
         pulseStarts[L] = millis();  //save the time of receipt
         digitalWrite(pulsePins[L], HIGH);
       }
     }
   }
 
   //the following code runs each time through loop()
   for (int p = 0; p < NUMBER_OF_PULSE_PINS; p++)
   {
     if (millis() - pulseStarts[p] >= pulseLength)  //has the pin been HIGH long enough ?
     {
       digitalWrite(pulsePins[p], LOW);   //take the pulse pin LOW
     }
   }
 
   for (int q = 0; q < NUMBER_OF_PULSE_PINS; q++)
   {
     if (millis() - pulseStarts[q] >= pulseLength)  //has the pin been HIGH long enough ?
     {
       digitalWrite(pulsePins[q], LOW);   //take the pulse pin LOW
     }
   }
 }
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image bubzy · Nov 28, 2015 at 01:58 PM 0
Share

http://forum.arduino.cc/index.php?topic=40001.0

avatar image KnightRiderGuy bubzy · Nov 28, 2015 at 07:39 PM 0
Share

Not sure how that helps as I don't know what i'm supposed to be looking at?

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

44 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity 3D with Arduino Code Question 2 Answers

Message Centre Does Not Display 0 Answers

UI Text is not being rebuilt/updated in edit mode, when changing text from OnInspectorGUI 1 Answer

Convert Message to Text Field Input 0 Answers

How to make Input Field with middle text align? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges