Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

NightRider with pcf8574 portexpanders


  • Please log in to reply
1 reply to this topic

#1 Hinnie

Hinnie

    New Member

  • Members
  • Pip
  • 9 posts

Posted 03 January 2011 - 12:09 PM

Hi,
The Night Rider is my first result with the netduino
I use two I2C PCF8574 portexpanders to 16 LEDs can be controlled.



On the clip you can see that the "pattern"on both portexpanders offered. The version of the firmware I used netduino: 4.1.0.5.

using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;

namespace NightRider
{
    public class Program
    {
        public static void Main()
        {
            new Thread( () => flashOnboardLed (200)).Start();

            I2CDevice MyI2CBus = new I2CDevice(null);
            I2CDevice.Configuration pcf8574_0 = new I2CDevice.Configuration(0x20, 400);
            I2CDevice.Configuration pcf8574_1 = new I2CDevice.Configuration(0x21, 400);
            I2CDevice.I2CTransaction[] xActions = new I2CDevice.I2CTransaction[1];

            int val = 0x0007;
            bool dir = false;
            byte[] cmd = new byte[1];

            while (true)
            {
                MyI2CBus.Config = pcf8574_0;
                cmd[0] = (byte)(val  ^ 0xFF) ;
                xActions[0] = I2CDevice.CreateWriteTransaction(cmd);
                MyI2CBus.Execute(xActions, 1000);

                MyI2CBus.Config = pcf8574_1;
                cmd[0] = (byte)((val >> 8) ^ 0xFF);
                xActions[0] = I2CDevice.CreateWriteTransaction(cmd);
                MyI2CBus.Execute(xActions, 1000);

                if ((val & 0x8000) > 0)
                    dir = true;
                if ((val & 0x0001) > 0)
                    dir = false;
                if (!dir)
                    val = val << 1;
                else
                    val = val >> 1;                
                Thread.Sleep(60);
            }
        }

        public static void flashOnboardLed(object flashTime)
        {
            OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);
            while (true)
            {
                led.Write(!led.Read());
                Thread.Sleep((int)flashTime);
            }
        }      
    }
}
Hinnie.

#2 karthick

karthick

    Member

  • Members
  • PipPip
  • 12 posts

Posted 16 September 2011 - 11:04 AM

can you tell me how to address the device?... you have addressed the pcf8574 as 0x20 and 0x21.... thanks in advance...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.