Need Help

can I connect an external button using a extender module ? other than connecting a button module?
does anyone have experience on these problem? or can I remove the button press event from a program and make the program start automatically without pressing a button?

What? You never “need” a button press, what makes you think that?

There’s no need to have a button connected.

BUT… you can connect a button to the Extender module. You need to know a little bit to wire it properly, but it’s not that hard if you really want to.

Brett


using Microsoft.SPOT;
 
using GT = Gadgeteer;
using Gadgeteer.Modules.GHIElectronics;
 
using Gadgeteer.Modules.Velloso;
 
namespace BlueToothMotorControl
{
    public partial class Program
    {
        Bluetooth bluetooth;
        int motorNumber;
        GT.Timer timer;
        Bluetooth.Client client;
        int speed;
 
        void ProgramStarted()
        {
            bluetooth = new Bluetooth(9);
            client = bluetooth.ClientMode;
            bluetooth.SetDeviceName("gmdTestDevice");
            bluetooth.SetPinCode("1234");
 
            bluetooth.DataReceived += new Bluetooth.DataReceivedHandler(bluetooth_DataReceived);
            bluetooth.BluetoothStateChanged +=
                        new Bluetooth.BluetoothStateChangedHandler(bluetooth_BluetoothStateChanged);
 
            speed = 0;
 
            button.ButtonPressed += new Button.ButtonEventHandler(button_ButtonPressed);
 
            timer = new GT.Timer(500);
            timer.Tick += new GT.Timer.TickEventHandler(timer_Tick);
 
            Debug.Print("Program Started");
        }
 
        void button_ButtonPressed(Button sender, Button.ButtonState state)
        {
            if (!button.IsLedOn)
            {
                timer.Start();
                button.TurnLEDOn();
            }
            else
            {
                timer.Stop();
                motorControllerL298.MoveMotor(MotorControllerL298.Motor.Motor1, 0);
                motorControllerL298.MoveMotor(MotorControllerL298.Motor.Motor2, 0);
                button.TurnLEDOff();
            }
        }
 
        void bluetooth_BluetoothStateChanged(Bluetooth sender, Bluetooth.BluetoothState btState)
        {
            if (btState == Bluetooth.BluetoothState.Connected)
            {
                client.Send("HELLO - sent by test module.");
            }
        }
 
        void bluetooth_DataReceived(Bluetooth sender, string data)
        {
            Debug.Print("Received: " + data);
 
            // Data should be sent in form: motor:1 speed:75
            // Motors: 1 or 2  with  speed: 0 - 100
            // Negative speed values will turn the motor in reverse direction.
            // Changing direction at high speed may damage motors or parts driven.
 
            int index = data.IndexOf("motor:");
 
            if (index != -1)
            {
                // parse the motor number from data.
                char c = data[index + 6];
                motorNumber = int.Parse(c.ToString());
            }
 
            index = data.IndexOf("speed:");
            if (index != -1)
            {
                // parse the speed value from data.
                speed = int.Parse(data.Substring(index + 6));
            }
        }
 
        void timer_Tick(GT.Timer timer)
        {
            if(button.IsLedOn)
            {
                if (motorNumber == 1)
                {
                    motorControllerL298.MoveMotor(MotorControllerL298.Motor.Motor1, speed);
                }
                else if (motorNumber == 2)
                {
                    motorControllerL298.MoveMotor(MotorControllerL298.Motor.Motor2, speed);
                }
            }
        }
    }
}

brett in this code how can I make this motor work without a button please help me…

these code is copied from

thnx. am asking that I dont have a buttom module and also i cannot buy it this moment am from sri lanka and they charge a lot mony on shipping these items pkease help me

I do not see a problem. all you need to do is move some code to automatically start.

move the start code from the button pressed routine to the program start method.

mike i don’t have much knowledge on coding which
part in need to be change please help me

I thought I told you how to do it? have you read the getting started ebook?

What do you want to do with this code though?

Please explain to us how you want your program to work. Under what conditions do you want to invoke the motor.

At the moment the button press code checks the current state of the buttton and stops the motors. All you have to do is figure out what you want to use instead of the button to control things.

If you have an extender module, and you have a standard push button and a resistor for a pullup, you can wire up something to make this work; the question is, again, what do you intend your application to do?

ok this is what i need to do, if i send “RUN” to gadgeteer bluetooth module using my pc and SSCom 3.2 Serial Console both motor should run if I sent " Stop " both motor should stop…can you help me on this problem brett please help me

remove everything related to your button
Remove the reference to the “button.IsLEDLit” because this is just the bit that checks if the motor is enabled.
Then code your bluetooth bit to start/stop motors.

But seriously, go back and learn to blink LEDs and the basics as Mike pointed out. That will really help you understand what other people’s code is doing !

thanx brett ok i’ll do it and also now am going to begin all from the beginning…wanna be a gadgeteer xpert…thnx all…in future i need all your help… thanx

we know, you already mentioned that in the topic title :wink:

brett…

how do I get the blutooth bit in this code? what is it
?
with what do I replace the “IsLEDon” reference?

the first thing you should do, after reading the beginners ebook, is to study the code you posted and make sure you understand what each line of code does. once you understand the code, you will realize how easy it is change it to do what you want.

it would take us less time to just post the modified code than keep answering your “how do I do it” question, but you would not have learned anything.

Like Mike, I prefer to teach someone how to fish, not just throw them a fish when they ask :slight_smile:

yep guys… I just understood… so I am going to learn How to fish…he he…thanx guys for ur motivation on me…KEEP IN TOUCH… will be back soon …