3x3x4 LedCube with Infrared photocell

Hello,

i want to controll my LED-Cube, with the FEZ Panda II.
The LED-Cube should start when the infrared photocell is broke through.

The LED-Cube is working without the infrared photocell but with it it doestn work.

Here is my C# source code:


using System;
using System.Threading;

using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

using GHIElectronics.NETMF.FEZ;

namespace FEZ_Panda_II_Application1
{
public class Program
{
public static void Main()
{

        InputPort In1 = new InputPort((Cpu.Pin)FEZ_Pin.Digital.Di0, true, Port.ResistorMode.PullUp);

        OutputPort layer_1 = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di26, false);
        OutputPort layer_2 = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di28, false);
        OutputPort layer_3 = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di35, false);
        OutputPort layer_4 = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di36, false);

        //Led 1-9
        OutputPort pin_1 = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di20, false);
        OutputPort pin_2 = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di22, false);
        OutputPort pin_3 = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di24, false);
        OutputPort pin_4 = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di30, false);
        OutputPort pin_5 = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di32, false);
        OutputPort pin_6 = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di34, false);
        OutputPort pin_7 = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di38, false);
        OutputPort pin_8 = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di40, false);
        OutputPort pin_9 = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di42, false);

        while (true)
        {
            if (In1.Read() == false)
            {
                layer_1.Write(false);
                layer_2.Write(true);
                layer_3.Write(true);
                layer_4.Write(true);

                pin_1.Write(!pin_1.Read());
                Thread.Sleep(150);
                pin_1.Write(!pin_1.Read());

                pin_2.Write(!pin_2.Read());
                Thread.Sleep(150);
                pin_2.Write(!pin_2.Read());

                pin_3.Write(!pin_3.Read());
                Thread.Sleep(150);
                pin_3.Write(!pin_3.Read());

                pin_6.Write(!pin_6.Read());
                Thread.Sleep(150);
                pin_6.Write(!pin_6.Read());

                pin_5.Write(!pin_5.Read());
                Thread.Sleep(150);
                pin_5.Write(!pin_5.Read());

                pin_4.Write(!pin_4.Read());
                Thread.Sleep(150);
                pin_4.Write(!pin_4.Read());

                pin_7.Write(!pin_7.Read());
                Thread.Sleep(150);
                pin_7.Write(!pin_7.Read());

                pin_8.Write(!pin_8.Read());
                Thread.Sleep(150);
                pin_8.Write(!pin_8.Read());

                pin_9.Write(!pin_9.Read());
                Thread.Sleep(150);
                pin_9.Write(!pin_9.Read());

                layer_1.Write(true);
                layer_2.Write(false);
                layer_3.Write(true);
                layer_4.Write(true);

                pin_9.Write(!pin_9.Read());
                Thread.Sleep(150);
                pin_9.Write(!pin_9.Read());

                pin_8.Write(!pin_8.Read());
                Thread.Sleep(150);
                pin_8.Write(!pin_8.Read());

                pin_7.Write(!pin_7.Read());
                Thread.Sleep(150);
                pin_7.Write(!pin_7.Read());

                pin_4.Write(!pin_4.Read());
                Thread.Sleep(150);
                pin_4.Write(!pin_4.Read());

                pin_5.Write(!pin_5.Read());
                Thread.Sleep(150);
                pin_5.Write(!pin_5.Read());

                pin_6.Write(!pin_6.Read());
                Thread.Sleep(150);
                pin_6.Write(!pin_6.Read());

                pin_3.Write(!pin_3.Read());
                Thread.Sleep(150);
                pin_3.Write(!pin_3.Read());

                pin_2.Write(!pin_2.Read());
                Thread.Sleep(150);
                pin_2.Write(!pin_2.Read());

                pin_1.Write(!pin_1.Read());
                Thread.Sleep(150);
                pin_1.Write(!pin_1.Read());

                layer_1.Write(true);
                layer_2.Write(true);
                layer_3.Write(false);
                layer_4.Write(true);

                pin_1.Write(!pin_1.Read());
                Thread.Sleep(150);
                pin_1.Write(!pin_1.Read());

                pin_2.Write(!pin_2.Read());
                Thread.Sleep(150);
                pin_2.Write(!pin_2.Read());

                pin_3.Write(!pin_3.Read());
                Thread.Sleep(150);
                pin_3.Write(!pin_3.Read());

                pin_6.Write(!pin_6.Read());
                Thread.Sleep(150);
                pin_6.Write(!pin_6.Read());

                pin_5.Write(!pin_5.Read());
                Thread.Sleep(150);
                pin_5.Write(!pin_5.Read());

                pin_4.Write(!pin_4.Read());
                Thread.Sleep(150);
                pin_4.Write(!pin_4.Read());

                pin_7.Write(!pin_7.Read());
                Thread.Sleep(150);
                pin_7.Write(!pin_7.Read());

                pin_8.Write(!pin_8.Read());
                Thread.Sleep(150);
                pin_8.Write(!pin_8.Read());

                pin_9.Write(!pin_9.Read());
                Thread.Sleep(150);
                pin_9.Write(!pin_9.Read());

                layer_1.Write(true);
                layer_2.Write(true);
                layer_3.Write(true);
                layer_4.Write(false);

                pin_9.Write(!pin_9.Read());
                Thread.Sleep(150);
                pin_9.Write(!pin_9.Read());

                pin_8.Write(!pin_8.Read());
                Thread.Sleep(150);
                pin_8.Write(!pin_8.Read());

                pin_7.Write(!pin_7.Read());
                Thread.Sleep(150);
                pin_7.Write(!pin_7.Read());

                pin_4.Write(!pin_4.Read());
                Thread.Sleep(150);
                pin_4.Write(!pin_4.Read());

                pin_5.Write(!pin_5.Read());
                Thread.Sleep(150);
                pin_5.Write(!pin_5.Read());

                pin_6.Write(!pin_6.Read());
                Thread.Sleep(150);
                pin_6.Write(!pin_6.Read());

                pin_3.Write(!pin_3.Read());
                Thread.Sleep(150);
                pin_3.Write(!pin_3.Read());

                pin_2.Write(!pin_2.Read());
                Thread.Sleep(150);
                pin_2.Write(!pin_2.Read());

                pin_1.Write(!pin_1.Read());
                Thread.Sleep(150);
                pin_1.Write(!pin_1.Read());

                layer_1.Write(true);
                layer_2.Write(true);
                layer_3.Write(false);
                layer_4.Write(true);

                pin_1.Write(!pin_1.Read());
                Thread.Sleep(150);
                pin_1.Write(!pin_1.Read());

                layer_1.Write(true);
                layer_2.Write(false);
                layer_3.Write(true);
                layer_4.Write(true);

                pin_1.Write(!pin_1.Read());
                Thread.Sleep(150);
                pin_1.Write(!pin_1.Read());
            }


        }
    }

}

}

Hi and welcome to the forum.

Can you please edit your post (the pencil icon at the top right of your post) and highlight your code and then click the 101010 icon (top left of the message box in edit mode).

OK, so really you need to tell us what doesn’t work.

The first thing that I would do is connect a GND wire from your breadboard to the Panda. Then, I think you should prove that the photocell circuit works in a quick project that just uses debug.print to check the level changes correctly when you block/unblock the receptor. Then once you know that works, try your project again.

(fundamentally, the goal here is to prove each part of your circuit and your code work independently, ie modularise your project and prove each module works as expected before integrating into a larger project)

Thank you for the fast answear.

When I connect a cable from the breadboard to the panda II GND, then the LED-Cube is working. But nothing happened when I block/unblock the photocell

Now I change the Di0 inputport to D11.

 InputPort In1 = new InputPort((Cpu.Pin)FEZ_Pin.Digital.Di11, true, Port.ResistorMode.PullUp);

At the first picture the green LED on the breadboard is working.

On the second pic i block the photocell with my finger and the green led is not working.

But all the time my LED Cube is working.

I want that my LED Cube start to work when the photocell is blocked and stop when the photocell another time is blocked.

And the third pic shows, how i connected the breadboard to the pandaboard. Green cable to D11 and the red one to GND.

New Project --> prove photocell only works and state changes correctly. Something there is not working as you expect. Or better still, just alternately connect Di0 to GND and 3v3 and prove that your code sees the change correctly - that bypasses the circuitry and will show you that code-wise you have working code, and then you will have to fix the photocell circuit

Show us the code that you used to test the green LED & cube at the same time. Something here doesn’t compute…

@ Ianlee, it’s already in the above code block - the code

if (In1.Read() == false)

is checking the digital pins’ state and running the LED cube display when it’s false. My suspicion is that however the circuit is wired is not triggering a state change on the pin, and proving the IO works by directly connecting to 3v3 and GND should prove that this code works as expected.

After looking at the pictures of the breadboard a little more closely, I suspect that the voltage drop over the LED might be having an impact here too. Please try connecting your digital input wire (the green one) to the same point the brown wire is connected and see if that then behaves differently

Oh, I see. I thought he was turning the green LED on using a pin. I didn’t notice it was wired inline with the IR detector. It didn’t make sense that he could turn the green LED on using logic but not the cube. I think you’re right about the voltage drop. tbasaran, put a meter on your detector and see what voltage level is being presented to the pin. You may need a transistor to give it a boost.

Hey,

thank you for your help.

Now its working with this code:


using System;
using System.Threading;

using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.Hardware;
using GHIElectronics.NETMF.FEZ;

namespace FEZ_Panda_II_Application1
{
    public class Program
    {
        public static void Main()
        {

            AnalogIn In1 = new AnalogIn(AnalogIn.Pin.Ain1);
            double impulse;
            

            OutputPort layer_1 = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di26, false);
            OutputPort layer_2 = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di28, false);
            OutputPort layer_3 = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di35, false);
            OutputPort layer_4 = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di36, false);

            //Led 1-9
            OutputPort pin_1 = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di20, false);
            OutputPort pin_2 = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di22, false);
            OutputPort pin_3 = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di24, false);
            OutputPort pin_4 = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di30, false);
            OutputPort pin_5 = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di32, false);
            OutputPort pin_6 = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di34, false);
            OutputPort pin_7 = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di38, false);
            OutputPort pin_8 = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di40, false);
            OutputPort pin_9 = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di42, false);

            while (true)
            {
                impulse = In1.Read();

                impulse = (impulse / 1023) * 3.3;
                Debug.Print(impulse.ToString());
                
                if (impulse < 2 )
                {
                    layer_1.Write(false);
                    layer_2.Write(true);
                    layer_3.Write(true);
                    layer_4.Write(true);

                    pin_1.Write(!pin_1.Read());
                    Thread.Sleep(150);
                    pin_1.Write(!pin_1.Read());

                    pin_2.Write(!pin_2.Read());
                    Thread.Sleep(150);
                    pin_2.Write(!pin_2.Read());

                    pin_3.Write(!pin_3.Read());
                    Thread.Sleep(150);
                    pin_3.Write(!pin_3.Read());

                    pin_6.Write(!pin_6.Read());
                    Thread.Sleep(150);
                    pin_6.Write(!pin_6.Read());

                    pin_5.Write(!pin_5.Read());
                    Thread.Sleep(150);
                    pin_5.Write(!pin_5.Read());

                    pin_4.Write(!pin_4.Read());
                    Thread.Sleep(150);
                    pin_4.Write(!pin_4.Read());

                    pin_7.Write(!pin_7.Read());
                    Thread.Sleep(150);
                    pin_7.Write(!pin_7.Read());

                    pin_8.Write(!pin_8.Read());
                    Thread.Sleep(150);
                    pin_8.Write(!pin_8.Read());

                    pin_9.Write(!pin_9.Read());
                    Thread.Sleep(150);
                    pin_9.Write(!pin_9.Read());

                    layer_1.Write(true);
                    layer_2.Write(false);
                    layer_3.Write(true);
                    layer_4.Write(true);

                    pin_9.Write(!pin_9.Read());
                    Thread.Sleep(150);
                    pin_9.Write(!pin_9.Read());

                    pin_8.Write(!pin_8.Read());
                    Thread.Sleep(150);
                    pin_8.Write(!pin_8.Read());

                    pin_7.Write(!pin_7.Read());
                    Thread.Sleep(150);
                    pin_7.Write(!pin_7.Read());

                    pin_4.Write(!pin_4.Read());
                    Thread.Sleep(150);
                    pin_4.Write(!pin_4.Read());

                    pin_5.Write(!pin_5.Read());
                    Thread.Sleep(150);
                    pin_5.Write(!pin_5.Read());

                    pin_6.Write(!pin_6.Read());
                    Thread.Sleep(150);
                    pin_6.Write(!pin_6.Read());

                    pin_3.Write(!pin_3.Read());
                    Thread.Sleep(150);
                    pin_3.Write(!pin_3.Read());

                    pin_2.Write(!pin_2.Read());
                    Thread.Sleep(150);
                    pin_2.Write(!pin_2.Read());

                    pin_1.Write(!pin_1.Read());
                    Thread.Sleep(150);
                    pin_1.Write(!pin_1.Read());

                    layer_1.Write(true);
                    layer_2.Write(true);
                    layer_3.Write(false);
                    layer_4.Write(true);

                    pin_1.Write(!pin_1.Read());
                    Thread.Sleep(150);
                    pin_1.Write(!pin_1.Read());

                    pin_2.Write(!pin_2.Read());
                    Thread.Sleep(150);
                    pin_2.Write(!pin_2.Read());

                    pin_3.Write(!pin_3.Read());
                    Thread.Sleep(150);
                    pin_3.Write(!pin_3.Read());

                    pin_6.Write(!pin_6.Read());
                    Thread.Sleep(150);
                    pin_6.Write(!pin_6.Read());

                    pin_5.Write(!pin_5.Read());
                    Thread.Sleep(150);
                    pin_5.Write(!pin_5.Read());

                    pin_4.Write(!pin_4.Read());
                    Thread.Sleep(150);
                    pin_4.Write(!pin_4.Read());

                    pin_7.Write(!pin_7.Read());
                    Thread.Sleep(150);
                    pin_7.Write(!pin_7.Read());

                    pin_8.Write(!pin_8.Read());
                    Thread.Sleep(150);
                    pin_8.Write(!pin_8.Read());

                    pin_9.Write(!pin_9.Read());
                    Thread.Sleep(150);
                    pin_9.Write(!pin_9.Read());

                    layer_1.Write(true);
                    layer_2.Write(true);
                    layer_3.Write(true);
                    layer_4.Write(false);

                    pin_9.Write(!pin_9.Read());
                    Thread.Sleep(150);
                    pin_9.Write(!pin_9.Read());

                    pin_8.Write(!pin_8.Read());
                    Thread.Sleep(150);
                    pin_8.Write(!pin_8.Read());

                    pin_7.Write(!pin_7.Read());
                    Thread.Sleep(150);
                    pin_7.Write(!pin_7.Read());

                    pin_4.Write(!pin_4.Read());
                    Thread.Sleep(150);
                    pin_4.Write(!pin_4.Read());

                    pin_5.Write(!pin_5.Read());
                    Thread.Sleep(150);
                    pin_5.Write(!pin_5.Read());

                    pin_6.Write(!pin_6.Read());
                    Thread.Sleep(150);
                    pin_6.Write(!pin_6.Read());

                    pin_3.Write(!pin_3.Read());
                    Thread.Sleep(150);
                    pin_3.Write(!pin_3.Read());

                    pin_2.Write(!pin_2.Read());
                    Thread.Sleep(150);
                    pin_2.Write(!pin_2.Read());

                    pin_1.Write(!pin_1.Read());
                    Thread.Sleep(150);
                    pin_1.Write(!pin_1.Read());

                    layer_1.Write(true);
                    layer_2.Write(true);
                    layer_3.Write(false);
                    layer_4.Write(true);

                    pin_1.Write(!pin_1.Read());
                    Thread.Sleep(150);
                    pin_1.Write(!pin_1.Read());

                    layer_1.Write(true);
                    layer_2.Write(false);
                    layer_3.Write(true);
                    layer_4.Write(true);

                    pin_1.Write(!pin_1.Read());
                    Thread.Sleep(150);
                    pin_1.Write(!pin_1.Read());
                }


            }
        }

    }
}]