So I set up Mono for my Raspberry Pi that I can use C#.
I'm converting a analog signal to a digital signal with a MCP3008. Now I want to use this signal in Unity3D to scale an Object.
This is my script actually:
Expand|Select|Wrap|Line Numbers
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Threading;
- using RaspberryPiDotNet;
- namespace RPi_Projekt4
- {
- class Program
- {
- static void Main(string[] args)
- {
- //# set up the SPI interface pins
- //# SPI port on the ADC to the Cobbler
- GPIOMem SPICLK = new GPIOMem(GPIOPins.Pin_P1_18, GPIODirection.Out);
- GPIOMem SPIMISO = new GPIOMem(GPIOPins.Pin_P1_23, GPIODirection.In);
- GPIOMem SPIMOSI = new GPIOMem(GPIOPins.Pin_P1_24, GPIODirection.Out);
- GPIOMem SPICS = new GPIOMem(GPIOPins.Pin_P1_25, GPIODirection.Out);
- int adcnum = 0;
- double read_adc0 = 0.0;
- while (true)
- {
- MCP3008 MCP3008 = new MCP3008(adcnum, SPICLK, SPIMOSI, SPIMISO, SPICS);
- // read the analog pin
- read_adc0 = MCP3008.AnalogToDigital;
- double millivolts = Convert.ToDouble(read_adc0) * (3300.0 / 1024);
- double volts = (Convert.ToDouble(read_adc0) / 1024.0f) * 3.3f;
- #if DEBUG
- System.Console.WriteLine("MCP3008_Channel: " + adcnum);
- System.Console.WriteLine("read_adc0: " + read_adc0);
- System.Console.WriteLine("millivolts: " + (float)millivolts);
- System.Console.WriteLine("distance: " + (float)distance);
- System.Console.WriteLine("volts: " + (float)volts);
- #endif
- Thread.Sleep(3000);
- }
- }
- }
- }
Can someone help please.