awesomejosephinewang-blog
awesomejosephinewang-blog
Josephine Wang
38 posts
AR / VR / C4D
Don't wanna be here? Send us removal request.
awesomejosephinewang-blog · 8 years ago
Video
tumblr
Day08_HW_ArduinoLCDScreen
0 notes
awesomejosephinewang-blog · 8 years ago
Video
tumblr
Day07_HW_Arduino(Unity)_CapacitySensor
*My dog doesn’t like eating his food. It’s exhausting that I have to encourage him to come to his bowl and praise him every time he takes a bite. Therefore I made this device to sense if he ever touch his bowl and play my voice automatically.
0 notes
awesomejosephinewang-blog · 8 years ago
Video
tumblr
Day07_HW_Unity_TouchScriptTest
0 notes
awesomejosephinewang-blog · 8 years ago
Video
tumblr
Day06_HW_ArduinoToUnity
Q: I couldn’t let the 2nd and 3rd lights to response to the value changes of potentiometer. According to the debug message the button seemed to work. Maybe there’s something wrong in the code.
---
/* Arduino Serial I/O  * Allows you to send simple commands to an arduino and to receive data back.  *   * Source based on: https://www.alanzucconi.com/2015/10/07/how-to-integrate-arduino-with-unity/  *  * ## Setup  * 1. Edit > Player Settings  * 2. .NET Compatibility Level = `.NET 2.0` */ using System.Collections; using System.Collections.Generic; using UnityEngine; using System.IO.Ports; public class MapSliderToColor : MonoBehaviour {     // Arduino User Inputs     [Tooltip("Open Arduino serial monitor, and look for the name of the port at the end of the phrase 'Arduino/Genuino Uno at...")]     public string portName = "COM5";     [Tooltip("The baudrate of the serial port")]     public int baudrate = 9600;     public float outputValue = 0f;     // Storage & I/O     private SerialPort stream;     string arduinoOutput;     int n = 3;     int step;     //Get User Input     private Light light1;     private Light light2;     private Light light3;     public GameObject lightSource1;     public GameObject lightSource2;     public GameObject lightSource3;     // Use this for initialization     void Start () {         Open (); // Opens the serial port (Arduino)         light1 = lightSource1.GetComponent<Light>();         light2 = lightSource2.GetComponent<Light>();         light3 = lightSource3.GetComponent<Light>();     }     // Update is called once per frame     void Update () {         try{             arduinoOutput = ReadFromArduino ();             outputValue = int.Parse (arduinoOutput);             if (outputValue == 100) {                 Debug.Log ("button press");                 n++;             }         }         catch{         }         WriteToArduino ("VOLT");         try{             arduinoOutput = ReadFromArduino();             outputValue = float.Parse (arduinoOutput);         }         catch{         }         //HERE         if (outputValue != -1) {             print ("Output Value: ");             Debug.Log (outputValue);             float valSliderTime = (outputValue / 5) * 1.0f;             step = n % 3;             switch (step) {             case 0:  //                float valSliderTime1 = (outputValue / 5) * 1.0f;                 light1.color = Color.HSVToRGB (0f, 255f, valSliderTime);                 print ("1: "); Debug.Log (valSliderTime);                 break;             case 1:  //                float valSliderTime2 = (outputValue / 5) * 1.0f;                 light2.color = Color.HSVToRGB (120f, 255f, valSliderTime);                 print ("2: "); Debug.Log (valSliderTime);                 break;             case 2: //                float valSliderTime3 = (outputValue / 5) * 1.0f;                 light3.color = Color.HSVToRGB (239f, 255f, valSliderTime);                 print ("3: "); Debug.Log (valSliderTime);                 break;             default:                 light1.color = Color.HSVToRGB (0f, 255f, 1.0f);                 light2.color = Color.HSVToRGB (120f, 255f, 1.0f);                 light3.color = Color.HSVToRGB (239f, 255f, 1.0f);                 break;             }         }     }     public void Open () {         // Opens the serial port         stream = new SerialPort(portName, baudrate);         stream.ReadTimeout = 20;         stream.Open();         Debug.Log ("Port Open!");         WriteToArduino ("INIT");         //this.stream.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);     }     public void WriteToArduino(string message)     {         // Send the request         stream.WriteLine(message + '\n');         stream.BaseStream.Flush();     }     public string ReadFromArduino()     {         try         {             return stream.ReadLine();         }         catch         {             return null;         }     } }
0 notes
awesomejosephinewang-blog · 8 years ago
Video
tumblr
Day05_HW_ARDUINO_StepperMotor
The step motor stopped right after I tried out these two conditions twice, not responding to anything even if I restarted Arduino. I might have accidentally broke it. :(
---
#include <AccelStepper.h> #define HALFSTEP 8 #define FULLSTEP 4
// You need the AccelStepper library for this sketch to run.  You can get it from here: http://aka.ms/AccelStepper
// The AccelStepper constructor expects the "pins" specified to be the ends of each coil respectively. // First the ends of the Blue/Yellow coil, then the ends of the Pink/Orange coil (Blue,Yellow,Pink,Orange)
// However, 28BYJ connector, ULN2003 board, and our current configuration is that pins are arranged in the proper FIRING order, // Blue, Pink, Yellow, Orange.
// No biggie, that just means that we need to pay attention to what pins on our Arduino, // map to which ends of the coils, and pass the pin numbers in in the proper sequence.  
// To help with that, I will specify my pin variables based on their color.
#define blue 2 #define pink 3 #define yellow 4 #define orange 5
//Keeps track of the current direction //Relative to the face of the motor. //Clockwise (true) or Counterclockwise(false) //We'll default to clockwise bool clockwise = true;
// How many steps to go before reversing // int targetPosition = 2048;  //2049 steps per rotation when wave or full stepping int targetPosition = 4096;  //4096 steps per rotation when half stepping
// Initialize with pin sequence IN1-IN3-IN2-IN4 for using the AccelStepper with 28BYJ-48 // Notice, I'm passing them as Blue, Yellow, Pink, Orange (coil ends order) not // Blue, Pink, Yellow, Orange (firing order). AccelStepper stepper1(HALFSTEP, blue, yellow, pink, orange);
int switchPin = 9; int value; int buzzPin = 8;
void setup() {
 pinMode(switchPin, INPUT);  pinMode(buzzPin,  OUTPUT);
 //Set the initial speed (read the AccelStepper docs on what "speed" means  stepper1.setSpeed(100.0);          //Tell it how fast to accelerate  stepper1.setAcceleration(50.0);  //Set a maximum speed it should exceed  stepper1.setMaxSpeed(4000.0);        //Tell it to move to the target position  stepper1.moveTo(targetPosition);  
}
void loop() {  stepper1.run();  value = digitalRead(switchPin);
 if(value == 0){    stepper1.setSpeed(50.0);    digitalWrite(buzzPin, HIGH);    tone(buzzPin, 1000, 25);    stepperDistanceCheck();    stepper1.run();  }  if(value == 1){    stepper1.setSpeed(500.0);    stepperDistanceCheck();    stepper1.run();  }
 stepperDistanceCheck();  //If the stepper still needs to move (distanceToGo() != 0)  //continue to advance (step) the motor  stepper1.run();
}
void stepperDistanceCheck(){    //Check to see if the stepper has reached the target:  if(stepper1.distanceToGo() == 0){    if(clockwise == true){      clockwise = false;  //Go counterclockwise now      stepper1.moveTo(0); //Go back to the "home" (original) position    } else {      clockwise = true;   //Go clockwise now      stepper1.moveTo(targetPosition);  //Go to the target position    }  }
}
0 notes
awesomejosephinewang-blog · 8 years ago
Video
vimeo
Day05_HW_AR_ExtendedTracking (TouchToDoStuff)
S.Y.S.T. (Stuff You Should Touch)
0 notes
awesomejosephinewang-blog · 8 years ago
Video
Day04_HW_AR_AccelerationGuitarPlayer
0 notes
awesomejosephinewang-blog · 8 years ago
Video
vimeo
Day04_HW_ARDUINO_TiltSwitch
Tumblr media
-----
int tonePin = 2; int statusPin1 = 13; int statusPin2 = 12; int switchPin1 = 6; int switchPin2 = 5;
int value1; int value2;
int pitch = 440; int length = 25;
void setup() {  pinMode(tonePin, OUTPUT);  pinMode(statusPin1, OUTPUT);  pinMode(switchPin1, INPUT);  pinMode(statusPin2, OUTPUT);  pinMode(switchPin2, INPUT);  Serial.begin(9600); }
void loop() {
 digitalWrite(tonePin, HIGH);
 value1 = digitalRead(switchPin1);  Serial.print("Value1: ");  Serial.println(value1);
 value2 = digitalRead(switchPin2);  Serial.print("Value2: ");  Serial.println(value2);
 Serial.print("Pitch: ");  Serial.println(pitch);
 Serial.print("Length: ");  Serial.println(length);
 if(value1 == 1)  {    digitalWrite(statusPin1, HIGH);    pitch = 1000;    tone(tonePin, pitch, length);  }  if(value1 == 0)  {    digitalWrite(statusPin1, LOW);    pitch = 440;    tone(tonePin, pitch, length);  }
 if(value2 == 1)  {    digitalWrite(statusPin2, HIGH);    length = 50; tone(tonePin, pitch, length);  }  if(value2 == 0)  {    digitalWrite(statusPin2, LOW);    length = 500; tone(tonePin, pitch, length);  }
 delay(500);  digitalWrite(tonePin, LOW); }
0 notes
awesomejosephinewang-blog · 8 years ago
Video
tumblr
Day03_HW_ARDUINO_PotentLight
0 notes
awesomejosephinewang-blog · 8 years ago
Video
vimeo
Day03_HW_AR_RemapAnimation
--
using System.Collections; using System.Collections.Generic; using UnityEngine; public class MapSliderToColor : MonoBehaviour {     //Get User Input     private Light light1;     private Light light2;     private Light light3;     public GameObject lightSource1;     public GameObject lightSource2;     public GameObject lightSource3;     const float hueSliderMin = 0.0f;     const float hueSliderMax = 359.0f;     const float satSliderMin = 0.0f;     const float satSliderMax = 255.0f;     const float valSliderMin = 0.0f;     const float valSliderMax = 255.0f;     [Range(hueSliderMin, hueSliderMax)] public float Light1HueSlider = 0.0f;     [Range(satSliderMin, satSliderMax)] public float Light1SaturationSlider = 255.0f;     [Range(valSliderMin, valSliderMax)] public float Light1ValueSlider = 255.0f;     [Range(hueSliderMin, hueSliderMax)] public float Light2HueSlider = 120.0f;     [Range(satSliderMin, satSliderMax)] public float Light2SaturationSlider = 255.0f;     [Range(valSliderMin, valSliderMax)] public float Light2ValueSlider = 255.0f;     [Range(hueSliderMin, hueSliderMax)] public float Light3HueSlider = 239.0f;     [Range(satSliderMin, satSliderMax)] public float Light3SaturationSlider = 255.0f;     [Range(valSliderMin, valSliderMax)] public float Light3ValueSlider = 255.0f;     //Helpers for positioning     float outMin = 0.0f;     float outMax = 1.0f;     // Use this for initialization     void Start () {         light1 = lightSource1.GetComponent<Light>();         light2 = lightSource2.GetComponent<Light>();         light3 = lightSource3.GetComponent<Light>();         Light1HueSlider = 0.0f; //Red         Light2HueSlider = 120.0f; //Green         Light3HueSlider = 239.0f; //Blue     }     float map(float inValue, float inMin, float inMax, float outMin, float outMax){         float inRange = inMax - inMin;         float delta = (inValue - inMin) / inRange;         float outRange = outMax - outMin;         float outValue = (outRange * delta) + outMin;         return outValue;     }     // Update is called once per frame     void Update () {         float hueSliderTime1 = map (Light1HueSlider, hueSliderMin, hueSliderMax, outMin, outMax);         float satSliderTime1 = map (Light1SaturationSlider, satSliderMin, satSliderMax, outMin, outMax);         float valSliderTime1 = map (Light1ValueSlider, valSliderMin, valSliderMax, outMin, outMax);         light1.color = Color.HSVToRGB(hueSliderTime1, satSliderTime1, valSliderTime1);         float hueSliderTime2 = map (Light2HueSlider, hueSliderMin, hueSliderMax, outMin, outMax);         float satSliderTime2 = map (Light2SaturationSlider, satSliderMin, satSliderMax, outMin, outMax);         float valSliderTime2 = map (Light2ValueSlider, valSliderMin, valSliderMax, outMin, outMax);         light2.color = Color.HSVToRGB (hueSliderTime2, satSliderTime2, valSliderTime2);         float hueSliderTime3 = map (Light3HueSlider, hueSliderMin, hueSliderMax, outMin, outMax);         float satSliderTime3 = map (Light3SaturationSlider, satSliderMin, satSliderMax, outMin, outMax);         float valSliderTime3 = map (Light3ValueSlider, valSliderMin, valSliderMax, outMin, outMax);         light3.color = Color.HSVToRGB (hueSliderTime3, satSliderTime3, valSliderTime3);     } }
0 notes
awesomejosephinewang-blog · 8 years ago
Video
tumblr
Day02_HW_ARDUINO_Buzzer+Potentiometer
Q: I hoped to have LEDs blink with the buzzer. However, when LED and buzzer are in parallel, only buzzer works; when they are in series, only LED works. How should I distribute the resistance in order to make them both work in the same circuit? (tried TinkerCad. It doesn’t show as accurately as the physical kit.)
--
int sensorValue; float voltage; int delayTime = 1000;
void setup() {  pinMode(12, OUTPUT);  pinMode(11, OUTPUT);  pinMode(10, OUTPUT);  Serial.begin(9600); }
void changeRate() {  // read the input on analog pin 0:  sensorValue = analogRead(A0);  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):  voltage = sensorValue * (5.0 / 1023.0);  // print out the value you read:  Serial.println(voltage);  delayTime = 1000 * (voltage / 5.00); }
void loop() {  changeRate();  digitalWrite(12, HIGH);  digitalWrite(11, LOW);  digitalWrite(10, LOW);  changeRate();  delay(delayTime);  digitalWrite(12, LOW);  changeRate();  delay(delayTime);  digitalWrite(11, HIGH);  changeRate();  delay(delayTime);  digitalWrite(11, LOW);  changeRate();  delay(delayTime);  digitalWrite(10, HIGH);  changeRate();  delay(delayTime);  digitalWrite(10, LOW);  changeRate();  delay(delayTime); }
0 notes
awesomejosephinewang-blog · 8 years ago
Video
Day02_HW_AR_CustomTarget
Q: How to attach audio source triggered when image target is found?
0 notes
awesomejosephinewang-blog · 8 years ago
Video
vimeo
Day01_HW_AR_ImageTargets
Trying Vuforia with customized image files.
0 notes
awesomejosephinewang-blog · 8 years ago
Video
tumblr
Day01_HW_ARDUINO_Blinking
Tumblr media
// Pin 13 has an LED connected on most Arduino boards. // give it a name: int ledR = 13; int ledB = 12;
const int buttonPin = 2; int buttonState = 0; int delayTime = 1000;
// the setup routine runs once when you press reset: void setup() {  // initialize the digital pin as an output.  pinMode(ledR, OUTPUT);  pinMode(ledB, OUTPUT);  // initialize the pushbutton pin as an input:  pinMode(buttonPin, INPUT);  delayTime = 1000; }
// the loop routine runs over and over again forever: void loop() {  // read the state of the pushbutton value:  buttonState = digitalRead(buttonPin);  if(delayTime <= 2){    delayTime = 1000;  }  if(buttonState == HIGH){    delayTime = delayTime/2;  }    digitalWrite(ledR, HIGH);   digitalWrite(ledB, LOW);    delay(delayTime);
   digitalWrite(ledR, LOW);    digitalWrite(ledB, HIGH);    delay(delayTime); }
0 notes
awesomejosephinewang-blog · 8 years ago
Video
Test: Scene changing, object triggering.
Question: How to force change camera view? transform.LookAt() didn’t work...
0 notes
awesomejosephinewang-blog · 8 years ago
Video
vimeo
0 notes
awesomejosephinewang-blog · 8 years ago
Video
Questions:
How to make hair shader? (tried so hard...)
How to let grass (in Terrain) collidable? They shouldn’t pass through the walls or dog’s legs.
0 notes