Advertisement
Guest User

Week 2 Lab a

a guest
Sep 6th, 2013
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.08 KB | None | 0 0
  1. using System;
  2. using System.Threading;
  3. using Microsoft.SPOT;
  4. using Microsoft.SPOT.Hardware;
  5.  
  6. namespace MFConsoleApplication3
  7. {
  8.     public class Program
  9.     {
  10.         public enum AdcChannel { ADC1, ADC2, ADC3, ADC4 };
  11.         public static void Main()
  12.         {
  13.             Debug.Print(
  14.                 Resources.GetString(Resources.StringResources.String1));
  15.            
  16.             //Week 2 Lab a
  17.  
  18.             SPI.Configuration SpiConf = new SPI.Configuration(Cpu.Pin.GPIO_Pin1, false, 1, 1, true, false, 16000, SPI.SPI_module.SPI1);
  19.             SPI Spi = new SPI(SpiConf);
  20.             ushort[] writeBuffer = new ushort[1];
  21.             ushort[] readBuffer = new ushort[1];
  22.             writeBuffer[0] = (ushort)AdcChannel.ADC2;
  23.             readBuffer[0] = 0;
  24.  
  25.             while (true)
  26.             {
  27.                 Spi.WriteRead(writeBuffer, readBuffer);
  28.                 ushort raw = readBuffer[0];
  29.                 float f = raw / 4096.0f * 5;
  30.                 Debug.Print("Read: " + f.ToString());
  31.                 Thread.Sleep(1000);
  32.             }
  33.  
  34.  
  35.         }
  36.  
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement