I bought an old Netduino1 and started to do simple projects using LEDs. I’m working on a project now to count from 0 to 30 in even integers using the for loop.
i’m a bit confused now on how to program my counter to restart back to 0 after reaching 30 and continue this process all over again.
i need help in this.
My initial program is this;
using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;
namespace NetduinoBinaryEvenIntegerCounter
{
public class Program
{
public static void Main()
{
int d = 2000; //2000 milliseconds
OutputPort D0 = new OutputPort(Pins.GPIO_PIN_D0, false); //Led0 connected to port D0
OutputPort D1 = new OutputPort(Pins.GPIO_PIN_D1, false); //Led1 conneted to port D1
OutputPort D2 = new OutputPort(Pins.GPIO_PIN_D2, false); //Led2 connected to port D2
OutputPort D3 = new OutputPort(Pins.GPIO_PIN_D3, false); //Led3 connected to port D3
OutputPort D4 = new OutputPort(Pins.GPIO_PIN_D4, false); //Led4 connected to port D4
for (int k = 0; k <= 30; k=k+2)
{
Light(k, D0, D1, D2, D3, D4); //call the method
Thread.Sleep(d); //sleep for 2000 milliseconds
Debug.Print("Send Value = " + k); // print what was sent to the LED
}
}
public static void Light(int i, OutputPort D0, OutputPort D1, OutputPort D2, OutputPort D3, OutputPort D4)
{
D0.Write((i & 1)>0); //00001 & 00001
D1.Write((i & 2)>0); //00010 & 00010
D2.Write((i & 4)>0); //00100 & 00100
D3.Write((i & 8)>0); //01000 & 01000
D4.Write((i & 16)>0); //10000 & 10000
}
}
}