Author Topic: Classes - mbed  (Read 783 times)

0 Members and 1 Guest are viewing this topic.

Offline c77asperTopic starter

  • Beginner
  • *
  • Posts: 5
  • Helpful? 0
Classes - mbed
« on: March 13, 2012, 08:22:47 AM »
Hey.
I have some problem.
#include "mbed.h"

I2C i2c(p9, p10);        // sda, scl
Serial pc(USBTX, USBRX); // tx, rx

const int addr = 0xB0; // define the I2C Address

int main() {
    char cmd[2];
    while(1) {
        cmd[0] = 0x00;            // pointer to command register
        cmd[1] = 255;
        i2c.write(addr, cmd, 2); // Send command string
        cmd[0] = 0x01;
        cmd[1] = 255;
        i2c.write(addr, cmd, 2);

        wait(0.07);              // Could also poll, 65ms is typical
       

   
    }
}

This is my code in mbed. Can i make a class????
I will use "cellbot" on my phone, so when i orees forward, the mbed gets a signal, F.
When it gets the signal F, it should drive forward.
So if i make a class, with the motors, i think it will be easier??
Can someone help me??

Offline joe61

  • Supreme Robot
  • *****
  • Posts: 417
  • Helpful? 16
Re: Classes - mbed
« Reply #1 on: March 13, 2012, 10:42:31 AM »
If you're doing something larger/more complicated, with lots of instances of the same thing that need to be managed separately, then classes might make sense. I can't see this being made simpler by adding more stuff to it.

Of course, if you want to practice OOP, then go ahead.

Joe

Offline c77asperTopic starter

  • Beginner
  • *
  • Posts: 5
  • Helpful? 0
Re: Classes - mbed
« Reply #2 on: March 14, 2012, 03:21:48 AM »
Well, can you help me then?
When i use cellbot, it will send the letter "F", when i drive forward, to the mbed.
When the program get the "F", then motor1 and motor2 should drive forward (255).
How will you make that?

Offline joe61

  • Supreme Robot
  • *****
  • Posts: 417
  • Helpful? 16
Re: Classes - mbed
« Reply #3 on: March 14, 2012, 07:05:29 AM »
Well, can you help me then?
When i use cellbot, it will send the letter "F", when i drive forward, to the mbed.
When the program get the "F", then motor1 and motor2 should drive forward (255).
How will you make that?

How do you make the motors go forward? Do that when you get the 'F'.

Maybe I don't understand what you're trying to ask.

Joe

Offline c77asperTopic starter

  • Beginner
  • *
  • Posts: 5
  • Helpful? 0
Re: Classes - mbed
« Reply #4 on: March 14, 2012, 04:44:59 PM »
Sorry for my english :) I am a danish guy :D

We have a robot, with to motors (wheels).
Motor 1 and motor 2.
In the code, we point to the register 0x00, which is motor1, and 0x01 is motor2.

We have a bluetooth adapter, where we connect to the robot, with our cellphone. We use the app called "cellbot".
When we press forward, at the joystick in cellbot, it will send the letter "F" to the mbed.

So when the mbed gets the letter "F", it should point to register 0x00 and 0x01 and set them to '255'.

If i press left, it will send the letter "S". And then it should point to register 0x00 and 0x01, and set 0x00 to '0' and 0x01 to '255'.

Hope you can see what i mean. We use a I2C bus, which control the motors..

Offline c77asperTopic starter

  • Beginner
  • *
  • Posts: 5
  • Helpful? 0
Re: Classes - mbed
« Reply #5 on: March 14, 2012, 04:49:50 PM »

Offline joe61

  • Supreme Robot
  • *****
  • Posts: 417
  • Helpful? 16
Re: Classes - mbed
« Reply #6 on: March 15, 2012, 06:21:03 AM »
Sorry for my english :) I am a danish guy :D

Don't worry about it. Your English is a lot better than my Danish.

Quote
Hope you can see what i mean. We use a I2C bus, which control the motors..


Are you asking how to code the i2c stuff? I really don't know much about mbed, but Pololu has links to a user guide which has a chapter on i2c, you might find that helpful. http://www.pololu.com/catalog/product/2150/resources

Joe

Offline c77asperTopic starter

  • Beginner
  • *
  • Posts: 5
  • Helpful? 0
Re: Classes - mbed
« Reply #7 on: March 15, 2012, 06:41:05 AM »
I will take a look at it :)
Thank you for your time!

 


Get Your Ad Here

data_list