![]() ![]() I then modified my sensor reading code to instantiate rain objects dependent on how moist it was. I also added a gameobject for the origin point of the rain where I could later instantiate rains. I then created a prefab out of the rain gameobject so that I could spawn in more. I then correctly aligned the camera object: I then created a new material which would be assigned to the rain in the Asset area:Īnd changed the 3D start size as seen below:Īnd set the speed to 25. I set the scale of the emmison to 10x10 and rotated the particle system by 180 degrees to be facing down. I began by creating a base rain particle effect using the particle system:Īnd changed the shape of the emmision to rectangle: I wanted to add rain which would change in heaviness based off the reading of the sensor. This video here is a longer explanation, the second video below this is a shorter demo if you don’t want the voiceover! Adding to the Unity World - Rain based off of the Moisture Sensor ¶ I fixed this and here is that updated Arduino code: After some review of my code, I realied I had foolishly plugged the dataline into a digital pin and not an analog. My sensor value didn’t change when dipped into water. ![]() SensorText.text = "Current Soil Moisture: " + sensorVal.ToString() + "%" Īnd it WORKED! I was getting Arduino sensor values in Unity! However, there was one major flaw. SensorVal = ((Mathf.RoundToInt(sensorVal * 100)) / 100) String fileData = System.IO.File.ReadAllText(destinationFile) String destinationFile = filePath + "1.txt" įile.Copy(sourceFile, destinationFile, true) Public const string filePath = "C:/Users/nicho/OneDrive/Desktop/CoolTerm Capture 15-55-02" Note that I got around the sharing violation by creating a copy of that file and opening the copy as opposed to the original, then after getting the data, I deleted the copy. I followed an example here and came up with this code: I needed to modify my code to get around this. Which I knew from previous experience meant I was trying to open an already opened file. This however didn’t work and consistently gave me this error: String fileData = System.IO.File.ReadAllText(filePath) Public const string filePath = "C:/Users/nicho/OneDrive/Desktop/CoolTerm Capture 15-55-02.txt" By clicking the options below, it was able to write to the text file:Īnd it sucsesfully put that text into a text file:Īnd with that I added special chars to the start of the data so I would be able to parse it later. This video lead me to a program called CoolTerm, which can be downloaded FOR WINDOWS here.Īnd it WORKED and the reader was reading the serial data CORRECTLY. Some of the info was lost, which meant it would be impossible to parse. With my previous Serial to TXT, it only read a few bits at a time, which is not what I wanted. Serial.println("&" + currentSoilMoisture + "&") Īnd was able to get serial readings. CurrentSoilMoisture = currentSoilMoisture + analogRead(soilMoisturePin) ĬurrentSoilMoisture = currentSoilMoisture/100.0 ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |