Notes About Working with Various Arduino & Netduino Microcontroller Boards

Thursday, July 12, 2012

Sample Netduino Code for SparkFun HDJD-S822 Color Sensor

The HDJD-S822 color sensor breakout board is available from Sparkfun. This code reads the color of incoming light (without the built-in white LED) and prints the RGB values to the Output panel. See the original Arduino code here.

Connections:
GSR1 --> D12
GSR0 --> D11
GSG1 --> D10
GSG0 --> D9
GSB1 --> D8
GSB0 --> D7
VR --> A0
VG --> A1
VB --> A2

using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.NetduinoPlus;


namespace HDJDS822
{
    public class Program
    {
        public static void Main()
        {
            int red = 0;
            int green = 0;
            int blue = 0;


            OutputPort GSR1 = new OutputPort(Pins.GPIO_PIN_D12, false);
            OutputPort GSR0 = new OutputPort(Pins.GPIO_PIN_D11, false);
            OutputPort GSG1 = new OutputPort(Pins.GPIO_PIN_D10, false);
            OutputPort GSG0 = new OutputPort(Pins.GPIO_PIN_D9, false);
            OutputPort GSB1 = new OutputPort(Pins.GPIO_PIN_D8, false);
            OutputPort GSB0 = new OutputPort(Pins.GPIO_PIN_D7, false);


            AnalogInput redpin = new AnalogInput(Pins.GPIO_PIN_A0);
            AnalogInput greenpin = new AnalogInput(Pins.GPIO_PIN_A1);
            AnalogInput bluepin = new AnalogInput(Pins.GPIO_PIN_A2);


            while (true)
            {
                red = redpin.Read() * 10;
                green = greenpin.Read() * 14;
                blue = bluepin.Read() * 17;


                Debug.Print("Red: " + red.ToString());
                Debug.Print("Green " + green.ToString());
                Debug.Print("Blue: " + blue.ToString());
                Thread.Sleep(1000);
            }
        }
    }
}



No comments:

Post a Comment