hi,
I am designing a mobile controlled LED indicator. which actually glows the 4 LEDs indicating the binary number of the key pressed on the mobile used as the remote.
connection details:
ht9170-> pin11 pin12 pin13 pin14
netduino-> D0 D1 D2 D3
Led(positive terminals)-> led0 led1 led2 led3
netduino-> d5 d7 d9 d11
led(negative terminals)-> led0 led1 led2 led3
netduino-> D4 D6 D8 D10
i am pasting the code that i attempted but it's not working properly.
using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;
namespace NetduinoApplication1
{
public class Program
{
public static void Main()
{
// write your code here
OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);
OutputPort ledp0 = new OutputPort(Pins.GPIO_PIN_D5, false);
OutputPort ledn0 = new OutputPort(Pins.GPIO_PIN_D4, false);
OutputPort ledp1 = new OutputPort(Pins.GPIO_PIN_D7, false);
OutputPort ledp2 = new OutputPort(Pins.GPIO_PIN_D9, false);
OutputPort ledp3 = new OutputPort(Pins.GPIO_PIN_D11, false);
OutputPort ledn1 = new OutputPort(Pins.GPIO_PIN_D6, false);
OutputPort ledn2 = new OutputPort(Pins.GPIO_PIN_D8, false);
OutputPort ledn3 = new OutputPort(Pins.GPIO_PIN_D10, false);
InputPort b0 = new InputPort(Pins.GPIO_PIN_D0, false, Port.ResistorMode.Disabled);
InputPort b1 = new InputPort(Pins.GPIO_PIN_D1, false, Port.ResistorMode.Disabled);
InputPort b2 = new InputPort(Pins.GPIO_PIN_D2, false, Port.ResistorMode.Disabled);
InputPort b3 = new InputPort(Pins.GPIO_PIN_D3, false, Port.ResistorMode.Disabled);
ledn0.Write(false);
ledn1.Write(false);
ledn2.Write(false);
ledn3.Write(false);
while (true)
{
if (b0.Read())
{
ledp0.Write(true);
}
if (b1.Read())
{
ledp1.Write(true);
}
if (b2.Read())
{
ledp2.Write(true);
}
if (b3.Read())
{
ledp3.Write(true);
}
}
}
}
I referred to the following table for the possible outputs of the different keys pressed by the remote mobile.
Key pressed DT0 DT1 DT2 DT3
------------ --- --- --- ---
1 H L L L
2 L H L L
3 H H L L
4 L L H L
where the D0,D1,D2,D3 represents the digital outputs of the DTMF chip(HT9170).
Kindly any one help me out.
DTMF chip coding problem
Started by Beowolf, Dec 06 2010 04:34 PM
2 replies to this topic
#1
Posted 06 December 2010 - 04:34 PM
#2
Posted 06 December 2010 - 05:42 PM
I'm just going to repost my answer to your last post here.
Using your provided code, you can either manually read using the Read() function, or receive events by attaching to the Output event like:
public class DTFM : IDisposable { private Thread ListenThread; private bool Listening; private int LastValue; private InputPort Binary1; private InputPort Binary2; private InputPort Binary4; private InputPort Binary8; public delegate void OutputHandler(object sender, int value); public event OutputHandler Output; public DTFM(Cpu.Pin Binary1, Cpu.Pin Binary2, Cpu.Pin Binary4, Cpu.Pin Binary8) { // Initialize the local InputPort's utilized by the DTFM this.Binary1 = new InputPort(Binary1, false, Port.ResistorMode.Disabled); this.Binary2 = new InputPort(Binary2, false, Port.ResistorMode.Disabled); this.Binary4 = new InputPort(Binary4, false, Port.ResistorMode.Disabled); this.Binary8 = new InputPort(Binary8, false, Port.ResistorMode.Disabled); // Initialize the listener thread Listening = true; ListenThread = new Thread(new ThreadStart(Listen)); ListenThread.Start(); } public void Dispose() { // Make the thread expire Listening = false; Thread.Sleep(10); // Force the thread dead just in case if (ListenThread.IsAlive) ListenThread.Abort(); // Free the InputPort's Binary1.Dispose(); Binary2.Dispose(); Binary4.Dispose(); Binary8.Dispose(); } public int Read() { int result = 0; // Build the current value from the DTFM if (Binary1.Read()) result += 1; if (Binary2.Read()) result += 2; if (Binary4.Read()) result += 4; if (Binary8.Read()) result += 8; } void Listen() { while (Listening) { // Don't execute if nothing is attached to the event if (Output != null) { int CurrentValue = 0; CurrentValue = Read(); // If the value has changed, throw a new event if (CurrentValue != LastValue) { LastValue = CurrentValue; Output(this, CurrentValue); } } // Wait Thread.Sleep(100); } } }
Using your provided code, you can either manually read using the Read() function, or receive events by attaching to the Output event like:
DTFM toneDecoder = new DTFM(Pins.GPIO_PIN_D0, Pins.GPIO_PIN_D1, Pins.GPIO_PIN_D2, Pins.GPIO_PIN_D3); toneDecoder.Output += new OutputHandler(ToneReceived);
#3
Posted 06 December 2010 - 05:58 PM
You might want to read up on how to interface those LEDs with the microcontroller too. Just put the positive on the output port, and the negative to the ground port.
You can make the leds match the input using this code:
You can make the leds match the input using this code:
public static void Main() { // setup LEDs OutputPort led1 = new OutputPort(Pins.GPIO_PIN_D5, false); OutputPort led2 = new OutputPort(Pins.GPIO_PIN_D5, false); OutputPort led4 = new OutputPort(Pins.GPIO_PIN_D5, false); OutputPort led8 = new OutputPort(Pins.GPIO_PIN_D5, false); // instantiate the DTFM driver DTFM toneDecoder = new DTFM(Pins.GPIO_PIN_D0, Pins.GPIO_PIN_D1, Pins.GPIO_PIN_D2, Pins.GPIO_PIN_D3); // main loop while (true) { int value = toneDecoder.Read(); // initialize leds led1.Write(false); led2.Write(false); led4.Write(false); led8.Write(false); // set LED array based on value switch(value) { case 0: // no leds lit break; case 1: led1.Write(true); break; case 2: led2.Write(true); break; case 3: led1.Write(true); led2.Write(true); break; case 4: led4.Write(true); break; case 5: led1.Write(true); led4.Write(true); break; case 6: led2.Write(true); led4.Write(true); break; case 7: led1.Write(true); led2.Write(true); led4.Write(true); break; case 8: led8.Write(true); break; case 9: led1.Write(true); led8.Write(true); break; case 10: led2.Write(true); led8.Write(true); break; case 11: led1.Write(true); led2.Write(true); led8.Write(true); break; case 12: led4.Write(true); led8.Write(true); break; default: // cannot have value for 13-16 break; } // wait for next round of input Thread.Sleep(200); } }
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users